简体   繁体   中英

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?

首先开始新的活动,然后完成旧的活动。

From the android docs :-

protected 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM