Detect the device is shutting down?

独自空忆成欢 提交于 2019-12-22 08:35:55

问题


In my android application i need to do some action if the device is turning off suddenly. Is there any way to detect the device is shutting down?


回答1:


Broadcast Action: Device is shutting down. This is broadcast when the device is being shut down (completely turned off, not sleeping). Once the broadcast is complete, the final shutdown will proceed and all unsaved data lost. Apps will not normally need to handle this, since the foreground activity will be paused as well.

This is a protected intent that can only be sent by the system.

May include the following extras:

EXTRA_SHUTDOWN_USERSPACE_ONLY a boolean that is set to true if this shutdown is only for userspace processes. If not set, assumed to be false. 

Constant Value: "android.intent.action.ACTION_SHUTDOWN"

Intent | Android Developers.

You have to configure the broadcast receiver to listen for this.



来源:https://stackoverflow.com/questions/20514698/detect-the-device-is-shutting-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!