这是我的 Activity 。
<activity
android:name=".MainActivity_Hard"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/title_activity_main_activity__hard"
android:noHistory="true"
android:screenOrientation="portrait" >
</activity>
我将其标记为 android:noHistory="true"因为我不想将屏幕添加到 Activity 堆栈中。
但是当我锁定屏幕并解锁时。 Activity 消失,出现上一个屏幕。这不应该发生。谁能告诉我为什么。
注意:它发生在 ICS(Samsung Galaxy Note)中,但不会发生在以前的设备(Gingerbread 等)
最佳答案
在您的 Activity 中设置 noHistory 属性意味着一旦用户离开该 Activity——调出锁定屏幕——它的 finish() 函数将自动调用,从而销毁它并返回到之前的产生它的 Activity 。
这通常用于启动画面类型的 Activity ,例如,仅充当启动器并且您不希望用户能够从子项返回到启动画面。
如果这不是您的 Intent ,那么您应该考虑删除 noHistory 属性并可能自己管理 Activity 生命周期。 (例如,如果您不希望您的 Activity 在堆栈中,则只需在它启动另一个 Activity 后立即调用 finish()。)
Whether or not the activity should be removed from the activity stack and finished (its finish() method called) when the user navigates away from it and it's no longer visible on screen — "true" if it should be finished, and "false" if not. The default value is "false". A value of "true" means that the activity will not leave a historical trace. It will not remain in the activity stack for the task, so the user will not be able to return to it.
关于android - 屏幕锁定时当前 Activity 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12182966/