On my android app for root user, I perform a shutdown with
su reboot -p
It works ok, but I noticed that the phone is shutdown almost instantly (as opposed from showing the shutdown animation, and probably doing other stuff).
Is this the correct way to shutdown an android phone programmatically? Are there some critical code that requires to be executed before shutdown?
In the Android source code, you can find the following:
/**
* Low-level function turn the device off immediately, without trying
* to be clean. Most people should use
* {@link android.internal.app.ShutdownThread} for a clean shutdown.
*
* @deprecated
* @hide
*/
@Deprecated
public static native void shutdown();
I think that this native function corresponds to your su reboot -p
. Moreover, you can see from the quoted code comment that you should use ShutdownThread to do a clean shutdown.
In ShutdownThread, Android does a bunch of things.
Thus, you can see that it's wrong to do su reboot -p
.