首先说下之所以去研究这个,主要是因为一个进程的内存限制是定死的,如果有什么特别耗内存的动作则会OOM,
使用多进程就可以使得我们一个apk所使用的内存限制加大几倍。
先来看看,如果按照一般的写法所用的代码
public class MultiProcessTestActivity extends Activity {
/** Called when the activity is first created. */
public static boolean isChecked = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
isChecked = true;
Log.i("MultiProcessTestActivity", isChecked + "");
int pid = android.os.Process.myPid();
String processNameString = "";
ActivityManager mActivityManager = (ActivityManager) this
.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager
.getRunningAppProcesses()) {
if (appProcess.pid == pid) {
processNameString = appProcess.processName;
}
Log.i("MultiProcessTestActivity", processNameString);
}
Intent mIntent = new Intent(this,MultiProcessTest_1_Activity.class);
startActivity(mIntent);
}
}
public class MultiProcessTest_1_Activity extends Activity{
@Ove