How can I tell when Android is shutting down?
I can put the functionality into a C++ daemon which is already running as root, or into an unprivileged Java app.
Can I distinguish shutting down from rebooting? (I only care about shutting down, and must not get a false-positive when rebooting.)
With a broadcast Receiver:
Apply an intent filter to your manifest declared broadcast receiver to listen to two actions: