Andorid 应用程序开启多进程
内存溢出,一个异常整个系统就崩溃等等,开启多进程能解决部分问题。
进入主题
问题:
1,多进程调试
Eclipse ADT 调试多进程
找到你的进程选择点击虫子即可调试
2,多进程之间变量共享,
开启多进程之后各个Activity之间的数据不能通过定义静态变量访问了,解决方案 在启动Activity 是使用Intent 发送。、
开始上代码
Activity声明是配置
<activity android:name="com.guotop.elearn.activity.app.yunpan.activity.YunPanUploadFileActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:process=":com.guotop.elearn.yunpan" > </activity>
我的工程的所有Activity都继承了BaseActivity所以我在直接里面加了方法
/** * 启动一个独立进程的 Activity * @param intent */ public void startAppcationActivity(Intent intent) { Gson gs = new Gson(); intent.putExtra("serverPort", L.SERVERPORT); intent.putExtra("serverIp", L.SERVERIP); intent.putExtra("cookie", L.COOKIE); intent.putExtra("userInfo", gs.toJson(L.userInfo)); startActivity(intent); }
//我的云盘 intent = new Intent(); intent.setClass(context, YunPanGridActivity.class); startAppcationActivity(intent);
写了个父类Activity给需要的继承
/** * * *@author: 李杨 *@time: 2014-4-23上午11:23:02 */ public class BaseApplicationActivity extends BaseActivity{ private String serverPort,serverIp; @Override protected void onCreate(Bundle savedInstanceState, Context sonContext) { super.onCreate(savedInstanceState,sonContext); Bundle ble = ((Activity)sonContext).getIntent().getExtras(); serverPort = ble.getString("serverPort"); serverIp = ble.getString("serverIp"); Gson gs =new Gson(); L.userInfo = gs.fromJson( ble.getString("userInfo"), UserInfo.class); L.COOKIE = ble.getString("cookie"); L.initServerAddress(serverIp, serverPort); L.mApplication =((Activity)sonContext).getApplication(); } }