android - 屏幕锁定时当前 Activity 消失

标签 android android-manifest android-activity android-lifecycle

这是我的 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()。)

android:noHistory

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/

相关文章:

java - 从 Activity 中的 Fragment 单击返回会显示空 Activity

android - Android Studio 中的 list 合并

android - 无法使用 YouTube Android Player API 播放某些 Youtube 视频

java - 透明度 webView

java - Android Activity 中是否需要私有(private)静态 `fields`

android - 为什么使用 android :configChanges is a bad practice

android - 从 Android Studio 运行应用程序时,在 Gradle 任务 processManifest.doLast 中编辑 AndroidManifest.xml 无效

android - 在 Activity 之间传递参数 - 空

android - 最佳实践 - 将 Activity 数据保存到 android 数据库

java - 从 PHP 检测 android java 客户端连接超时