检测设备被关闭? [英] Detect the device is shutting down?

查看:254
本文介绍了检测设备被关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序,我需要做一些动作,如果设备突然关闭。有什么办法来检测设备正在关闭?

解决方案
  

广播事件:设备正在关闭。这是广播时   设备被关闭(完全关闭,不睡觉)。一旦   广播结束后,最终的关闭将继续,并且所有   未保存的数据丢失。应用程序通常不需要处理这一点,因为   前台活动将被暂停为好。

     

这是只能由系统发送一个受保护的意图。

可包括以下额外的:

  EXTRA_SHUTDOWN_USERSPACE_ONLY被设置为true,如果此关机仅适用于用户空间的进程一个布尔值。如果没有设置,假设是错误的。
 

恒值: android.intent.action.ACTION_SHUTDOWN

意向| Android开发者

您必须配置广播接收器来监听这个

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?

解决方案

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.

这篇关于检测设备被关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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