简体   繁体   中英

Intent onDestroy() always being called with back button

I appear to have the opposite issue to every other post on the topic I have come across. Others find that onDestroy() is not always called but I find it always and immediately is.

I am checking whether it is called with the following:

@Override
protected void onDestroy() {
    super.onDestroy();
    Log.d(TAG, "onDestroy");
}

This log code is triggered immediately after either clicking back or using my actionbar button which just calls the home activity as an intent.

I have looked around but everyone says the lifecycle should look like this: http://developer.android.com/images/activity_lifecycle.png

This behaviour is not limited to a single app; I have tried downloading some example code and adding in the above debugging code only to find the same behaviour. It is also not limited to a single android version; I have tried 2.1 and 2.3 in the emulator and also 4.0.2 on a physical device.

Any ideas of what I might be doing wrong?

pressing back key actually provokes finish() method on your activity, and it causes your activity to be paused->stopped->destroyed

so technically this behavior is functional as expected.

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