Recently, when I was working on a project, I accidentally found a way to completely exit the android program. I wondered why I was embarrassed to find an effective way to completely exit the android program, I cannot help but feel a little emotion. I am afraid to share this with you. I hope you can continue to discuss this issue.
The method is very simple. It is actually a window. Once you know it, you will understand it. Use jni to call exit in linux. The specific implementation is as follows:
package com.example.bitmaptest;import android.util.Log;public final class AppUtils {private static final String TAG = "AppUtils";static {System.loadLibrary("appUtils");}private native void native_exit();public void exit() {Log.d(TAG, "exit");if (listener != null) {listener.onExit();}native_exit();}public static interface OnExitListener {void onExit();}private OnExitListener listener;public void setOnExitListener(OnExitListener listener) {this.listener = listener;}public OnExitListener getOnExitListener() {return listener;}}
Jni implementation is as follows:
JNIEXPORT void JNICALL Java_com_example_bitmaptest_AppUtils_native_1exit (JNIEnv * env, jobject obj) {exit(0);return;}
Note: after this method is used, the log will find the following content:
06-15 09:20:49. 316: I/ActivityManager (805): Process com. example. bitmaptest (pid 5784) has died.
06-15 09:20:49. 316: I/WindowState (805): WIN DEATH: Window {4214d2f0 u0 com. example. bitmaptest/com. example. bitmaptest. MainActivity}
However, it doesn't matter if you want to quit the app.