简体   繁体   English

为什么要调用新Activity的onDestroy()?

[英]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.

相关问题 为什么只调用第一个活动的`onDestroy`,而不调用其他活动? - Why only the first activity's `onDestroy` is called, not other activities? 片段的onActivityCreated()在Activity的onDestroy()之后调用 - Fragment's onActivityCreated() is called after onDestroy() of Activity Activity OnDestroy从未调用过? - Activity OnDestroy never called? 从后台滑动后未调用Activity的onDestroy方法 - Activity's onDestroy method is not being called after swiping from background 如果未调用活动的 onDestroy() 方法,如何更新远程数据库中的状态? - How to update status in remote database if the activity's onDestroy() method is not called? 当我单击通知并进入活动时,为什么调用onDestroy()? - Why is onDestroy() called when I click on a notification and go to my activity? 在PAD中返回父活动时为何调用onDestroy? - Why onDestroy called when returning to parent activity in PAD? 为什么在返回父活动时总是调用 onDestroy? - Why is onDestroy always called when returning to parent activity? onDestroy()在调用特定活动时调用 - onDestroy() Called when specific Activity is Called 通过滑动从后台删除活动后未调用Activity的onDestroy()方法 - Activity's onDestroy() method not called after removing activity from background by swiping
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM