One way to completely exit the android Program

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.