Activity调用finish却不立即执行onDestory

遇到一个奇怪的问题,我将打开的Activity放在一个栈里面进行管理,然后当我要关闭所有的Activity的时候

public void CloseAllActivity(){
		if(activityStack==null)return;
		while(true){
			Activity activity = currentActivity();
			if(activity == null){
				break;
			}
			activity = popActivity();
			activity.finish();
		}
	}
虽然每个Activity的finish方法我都调用了,可是他们的onDestory方法缺不是立即执行,而是不知在某个时候执行,后来发现调用了finish后onDestory不是立即被调用,只是我的一厢情愿。

但是随之而来出现了另外的一个问题,那就是我调用了Activity A的finish方法后,他的onDestory方法还没有被执行,但是我再打开这个Activity他走的是onCreate而不是onNewIntent,按理说我设置了android:launchMode="singleTask"这个Activity要是还在栈里面就不会重新创建而是走onNewIntent,难道我执行了finish但是他没有执行onDestory方法,Android根据这个finish方法被执行了,然后就任务已经不在栈里面了,所以就走了onCreate而不是onNewIntent方法?这个只是我根据现象做的假设,还要等有时间去看一下源码验证一下

void com.hyfsoft.viewer.HYFDocviewer.onDestroy()
Perform any final cleanup before an activity is destroyed. This can happen either because the activity is finishing (someone called finish on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing method. 




boolean android.app.Activity.isFinishing()
Check to see whether this activity is in the process of finishing, either because you called finish on it or someone else has requested that it finished. This is often used in onPause to determine whether the activity is simply pausing or completely finishing.


Returns:
If the activity is finishing, returns true; else returns false.
See Also:
finish

你可能感兴趣的:(android,null,System,任务)