A way to completely exit a new Android program

Source: Internet
Author: User

When I recently made a project, I accidentally discovered a way to get the Android program to quit completely, and thinking back to find an effective way to get the Android program to completely quit when the embarrassment, some feeling. Here dare not alone, and share with you, is also a point, I hope that Daniel out to continue to explore this issue.

The method is very simple, actually is a layer of window paper, know, will understand. Call the Linux system call exit with JNI. Here are the specific implementations:

Package Com.example.bitmaptest;import Android.util.log;public Final class Apputils {private static final String TAG = "App Utils "; static {system.loadlibrary (" Apputils ");} Private native void Native_exit ();p ublic 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;}}

The JNI implementation is as follows:

jniexport void Jnicall java_com_example_bitmaptest_apputils_native_1exit  (jnienv * env, Jobject obj) {exit (0); return;}

Note: After using this method, the following is found in log:

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}

But because of the need to completely quit the app, so I think it doesn't matter.


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.