继承自ActivityGroup类的主类,调用finish方法时,自己可以onDestroy,但其包含的子Activity没有finish。
采用了方法1:
1、获取当前Activity,然后显示调用 finish方法
Activity pActivity = getLocalActivityManager().getCurrentActivity(); pActivity.finish();
结果【看调试信息:子Activity的onDestroy方法没有调用】
2、向子Activity 发送广播,让其接受到广播后,自己调用finish方法。
sendBroadcast(new Intent(ACTION_INTENT_KILLSELF_MSG)); private BroadcastReceiver mReceiveBroadcast = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(ACTION_INTENT_KILLSELF_MSG)) { finish(); } } };
结果【收到广播,但子Activity的onDestroy方法任然没有调用】
3、调用ActivityGroup中的destroyActivity方法
getLocalActivityManager().destroyActivity("***Activity", true);结果【看调试信息:子Activity的onDestroy方法没有调用】
4、最后郁闷,采用查询后台进程,杀死的方法,最终解决了。
final ActivityManager am = (ActivityManager) getSystemService(Service.ACTIVITY_SERVICE); Log.d("FinishApplication :", getPackageName()); am.killBackgroundProcesses(getPackageName());
结果【程序结束后,手机后台运行进程没有了我的应用程序】