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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值