Determine if phone has been rebooted

梦想的初衷 提交于 2019-12-02 02:17:11

Yes you can do that using Application class and the Non-Static broadcast Receiver ACTION_SHUTDOWN. The Application class got started in two cases

  1. Android Device Boot
  2. Your Application Starts after it was "Force-Close" it.

When ACTION_SHUTDOWN received use your application Shared-preferences or database to save a boolean shutdown = true when application class starts check this boolean. If it is true then the device is booting , else the user forced your app to stop.

To get more info you can read the following post that I wrote and try the code example in which, I added

  1. Application Class
  2. Boot Broadcast Receiver (To Show the difference and that both starts)
  3. Shutdown broadcast receiver that is register in the Application calss
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!