Activity转发

实现类似于J2EE web开发中的servlet转发效果,用于往他人程序中嵌入插件。做法为

package com.flrsdk.activity;

import com.flrsdk.service.FloatService;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class PreActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.main);

        System.out.println("Pre启动");
        Intent service = new Intent();
        service.setClass(this, FloatService.class);
        startService(service);
        Intent intent=new Intent();
        intent.setAction("com.mh.sdk.demo.MainActivity");
        startActivity(intent);
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        Intent serviceStop = new Intent();
        serviceStop.setClass(this, FloatService.class);
        stopService(serviceStop);
    }

    @Override
    protected void onRestart() {
        // TODO Auto-generated method stub
        super.onRestart();
            //第二次进入的时候说明有戏退出了,立马结束掉当前activity
            finish();
    }

}

将该activity配置为对话框形式,

            android:theme="@android :style/Theme.Dialog" 

否则很容易看出来activity经过了一次跳转。

评论

暂无评论