没有返回键破坏活动? [英] Did back key destroy an activity?

查看:145
本文介绍了没有返回键破坏活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有定义如下活动:

    <activity android:name="com.example.ui.HomeActivity"
        android:alwaysRetainTaskState="true"/>

一个很奇怪的是,在模拟器上运行时,和返回键是pressed,该活动被破坏(我看到的onDestroy()调用日志)。但我的Nexus One手机上运行时,和返回键是pressed,该活动不被破坏(我没看到的onDestroy()调用日志)。

A strange thing is that, when running on emulator, and the back key is pressed, the activity was destroyed (I saw onDestroy() called in log). But when running on my Nexus One phone, and the back key is pressed, the activity is not destroyed (I didn't see onDestroy() called in log).

有人能告诉我为什么吗?

Could someone tell me why?

感谢。

推荐答案

在活动是在后台(后pressing后退键)它总是停止,但系统还可以决定摧毁它(例如,当系统资源低)。你无法确定何时将被销毁。

When activity is in the background (after pressing Back key) it is always stopped but System can also decide to destroy it (eg. when system resources are low). You can't determine when it will be destroyed.

活动还可以通过调用完成销毁() 。您可以确定通过检查 isFinishing()的onPause 或的的onStop 回调。

Activity can also be destroyed by calling finish(). You can determine that by checking isFinishing() status in onPause or onStop callback.

不要在的onDestroy回调不算数。如果系统会杀死活性它不会被调用。

Do not count on onDestroy callback. If system will kill activity it wont be called.

这篇关于没有返回键破坏活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆