[英]Why new Activity's onDestroy() is called?
My code destroy my current activity and start a new activity, like below: 我的代码破坏了我当前的活动并开始了一个新的活动,如下所示:
Intent intent = myActivity.getIntent();
myActivity.finish(); //Destroy my activity
myActivity.startActivity(intent); //Start my new activity
It works, the previous activity is destroyed and new activity starts, but AFTER start the new activity, the activity's onDestroy()
method is called, why? 它的工作原理,以前的活动被破坏,新的活动启动,但启动后新的活动,该活动的
onDestroy()
方法被调用,为什么呢?
首先开始新的活动,然后完成旧的活动。
From the android docs :- 从android docs :-
protected void onDestroy ()
受保护的void 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.
这可能是由于活动即将完成(有人在其上称为finish()) ,或者因为系统正在临时销毁该活动实例以节省空间。您可以使用isFinishing()方法区分这两种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.