Shutdown Events in Android

前端 未结 2 489
旧巷少年郎
旧巷少年郎 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 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.

提交回复
热议问题