电池耗尽时会调用什么Android方法? [英] What Android methods are called when battery dies?
问题描述
当我的Android设备上的电池耗尽时,在设备的关闭电源"阶段会调用Activity和Fragment类(如果有)中的哪些方法?
When the battery on my Android device dies what methods in the Activity and Fragment classes (if any) are called during the "Powering Off" stage of the device?
此外,如果用户当前正在查看我的应用程序中的屏幕,并且按住电源按钮并选择关闭,那么调用/不调用事件是否与电池耗尽并自动关闭时相符?
Also, if a user is currently looking at a screen in my app and they hold the power button and choose switch off, do the events called/not called coincide with when the battery is depleted and shuts down automatically?
暂停吗?
OnStop?
OnDestroy?
OnDestroy?
OnDetach?
奖金: 我是否有足够的时间将少量数据保存到Web服务器?
Bonus: Will I have enough time to save a small amount of data to a web server?
为弄清楚设备电池完全"没电时的死机"现象,不再接受任何输入,并且屏幕上弹出消息框/加载屏幕,指出关闭电源".设备关闭后不久.
To clarify "dies" when the device's battery is 'completely' dead, accepts no more input and a message box/loading screen pops up on the screen stating "Powering Off". Shortly there after the device switches off.
在电话关闭之前,我只需要足够的时间来保存表单状态,我有一个策略可以清除电话无法关闭时保存的数据,但是我想尽可能地接近电话关闭状态(超过一分钟真的是没有意义的.
I just need enough time to save a forms state before the phone switches off, I have a strategy to clean the saved data should the phone not switch off, but I want to get as close to the phone switching off as possible (any more than a minute is pointless really).
推荐答案
当电池电量达到0.5%时,onDestroy会在所有对象上调用
onDestroy is called on everything when the battery reaches 0.5%
由于电池电量不足或电量不足,在关闭过程中没有指定的时间必须执行任何操作,这取决于特定的手机电池而不是系统,因此您可能有足够的时间来保存数据到某些电话上的Web服务器,而其他电话上没有.从实验上讲,我只能在调用onDestroy之前向已经写入的文件写一小段代码.
There is no specified time that you have to do anything in the shutdown process resulting from low/dead battery, that would be dependent on the specific phone battery and not the system, so you may have enough time to save data to a web server on some phones but not others. Experimentally, I have only been able to write a short line to a file I was already writing to before onDestroy was called and nothing more.
这篇关于电池耗尽时会调用什么Android方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!