Shutdown Events in Android

前端 未结 2 479
旧巷少年郎
旧巷少年郎 2021-01-05 10:00

Is it possible to intercept a phone shutdown event or perhaps use a different hack around this? I have an always running service that\'s part of a non-market application whi

相关标签:
2条回答
  • 2021-01-05 10:47

    Build a broadcast receiver at catches the ACTION_SHUTDOWN intent.

    In the onReceive() method you can accomplish what you are trying to do.

    http://developer.android.com/reference/android/content/Intent.html#ACTION_SHUTDOWN

    0 讨论(0)
  • 2021-01-05 11:03

    You could try registering a Shutwdown hook using the Runitme addShutdownHook(Thread hook) method.

    Aditionally the method reference states:

    If runFinalizersOnExit(boolean) has been called with a true argument, garbage collection and finalization will take place after all hooks are either finished or have failed. Then the VM terminates.

    So, theoretically the VM won't terminate until your thread finish.

    0 讨论(0)
提交回复
热议问题