Android, how to determine if a reboot occurred?

前端 未结 4 1739
慢半拍i
慢半拍i 2021-01-14 09:33

How would I programmatically determine when an android device has rebooted (whether on its own, or user initiated) ?

4条回答
  •  孤独总比滥情好
    2021-01-14 10:25

    Set up a BroadcastReceiver and register it in your manifest to respond to the android.intent.action.BOOT_COMPLETED system even. When the phone starts up the code in your broadcastreceiver's onReceive method will run. Make sure it either spawns a separate thread or takes less than 10 seconds, the OS will destroy your broadcastreceiver thread after 10 seconds.

提交回复
热议问题