实现类似于J2EE web开发中的servlet转发效果,用于往他人程序中嵌入插件。做法为
1package com.flrsdk.activity; 2 3import com.flrsdk.service.FloatService; 4 5import android.app.Activity; 6import android.content.Intent; 7import android.os.Bundle; 8 9public class PreActivity extends Activity { 10 @Override 11 protected void onCreate(Bundle savedInstanceState) { 12 // TODO Auto-generated method stub 13 super.onCreate(savedInstanceState); 14// setContentView(R.layout.main); 15 16 System.out.println("Pre启动"); 17 Intent service = new Intent(); 18 service.setClass(this, FloatService.class); 19 startService(service); 20 Intent intent=new Intent(); 21 intent.setAction("com.mh.sdk.demo.MainActivity"); 22 startActivity(intent); 23 } 24 25 @Override 26 protected void onDestroy() { 27 // TODO Auto-generated method stub 28 super.onDestroy(); 29 Intent serviceStop = new Intent(); 30 serviceStop.setClass(this, FloatService.class); 31 stopService(serviceStop); 32 } 33 34 @Override 35 protected void onRestart() { 36 // TODO Auto-generated method stub 37 super.onRestart(); 38 //第二次进入的时候说明有戏退出了,立马结束掉当前activity 39 finish(); 40 } 41 42}
将该activity配置为对话框形式,
android:theme="@android :style/Theme.Dialog"
否则很容易看出来activity经过了一次跳转。