Activity转发

来源:互联网 发布:黑猫微圈源码 编辑:程序博客网 时间:2024/06/02 06:33
实现类似于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 {@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.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);}@Overrideprotected void onDestroy() {// TODO Auto-generated method stubsuper.onDestroy();Intent serviceStop = new Intent();serviceStop.setClass(this, FloatService.class);stopService(serviceStop);}@Overrideprotected void onRestart() {// TODO Auto-generated method stubsuper.onRestart();//第二次进入的时候说明有戏退出了,立马结束掉当前activityfinish();}}

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

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

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

原创粉丝点击