-1

I want to call a method before shotdown or restart an android phone.

  • Does this answer your question? [Is there any way to receive a notification when the user powers off the device?](https://stackoverflow.com/questions/2190126/is-there-any-way-to-receive-a-notification-when-the-user-powers-off-the-device) – javdromero Jun 28 '21 at 16:35
  • 1
    Please note that even if you find a way, it will only work for a clean shutdown. The device crashing, running out of power, the battery being pulled, the power button being held for a hard reset would still not trigger it – Gabe Sechan Jun 28 '21 at 16:36

1 Answers1

1

As they said on the official site

Broadcast Action: Device is shutting down. This is broadcast when the device is being shut down (completely turned off, not sleeping). Once the broadcast is complete, the final shutdown will proceed and all unsaved data lost. Apps will not normally need to handle this, since the foreground activity will be paused as well. As of Build.VERSION_CODES#P this broadcast is only sent to receivers registered through Context.registerReceiver.

Amjad Alwareh
  • 2,926
  • 22
  • 27