[英]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.
其他人发现onDestroy()并不总是被调用,但我总是立即发现它。
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 我环顾四周,但每个人都说生命周期应该是这样的: 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;
它也不仅限于一个Android版本; I have tried 2.1 and 2.3 in the emulator and also 4.0.2 on a physical device.
我在模拟器中尝试过2.1和2.3,在物理设备上也尝试过4.0.2。
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 按回键实际上会激活你的活动的
finish()
方法,它会导致你的活动被暂停 - >停止 - >被破坏
so technically this behavior is functional as expected. 所以从技术上讲,这种行为是按预期运作的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.