简体   繁体   English

活动在接近传感器的屏幕上消失

[英]Activity disappears on screen off by proximity sensor

I've an activity dialog that is displayed when the activity receives a custom broadcast intent filter. 我有一个活动对话框,当活动接收到自定义的广播意图过滤器时会显示该对话框。 The application uses the proximity sensor to turn the screen off. 该应用程序使用接近传感器关闭屏幕。 But when the screen turns on again, the dialog disappears. 但是,当屏幕再次打开时,对话框消失。 How can I prevent the dialog from disappearing? 如何防止对话框消失?

use flags in Activity 在活动中使用标志

When screen off it just recreate activity then onCreate method is call so Activity re initialize it self and all content is reloaded 当屏幕关闭时,它只是重新创建活动,然后调用onCreate方法,因此Activity会自行对其进行初始化,并重新加载所有内容

If you set configChanges flag in your activity it does not recreate the activity just resume it 如果您在活动中设置configChanges标志,则它不会重新创建活动,而只是恢复它

Do this is your manifest file where you define your activity 这是清单文件,您可以在其中定义活动

<activity
            android:name=".MyActivity"
            android:configChanges="orientation|keyboardHidden|keyboard"
            android:label="MYLabel" >
        </activity>

yourDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); yourDialog.getWindow()。addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

This will not let screen go off while your dialog is visible. 当您的对话框可见时,这不会让屏幕关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM