Intent onDestroy() always being called with back button

匿名 (未验证) 提交于 2019-12-03 08:54:24

问题:

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?

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!