Android Development Two exit program mode (KILLPROCESS,SYSTEM.EXIT)

Source: Internet
Author: User

killprocess:

In Android we can write if we want the process of the program to end:

Android.os.Process.killProcess (Android.os.Process.myPid ());

This allows you to end the process of the current program from the operating system.

Note: All activity in Android is in the main process and can be set to start a different process in androidmanifest.xml, and the service is not a separate process or a thread.
When you kill the process of the current program, that is, all threads of the entire program will end, the service will stop, and the entire program exits completely.

System.exit:

When we write Java programs we must have used System.exit (0), which means to quit the JVM (Java Virtual Machine), in the same way as Android, We can imagine that the VMs are out of course the program that executes System.exit will exit completely and the memory is freed.

Note: In the Android phone to see the currently running process can also see the "Background cache process", you will find that many of the exiting program is also in the background cache process, if you do not let the program in the background cache then can use System.exit (0); To quit the program, You can clear the background cache of this process.

System.exit (0), the difference between system.exit (1):

Parameters 0 and 1 represent the state of exit, 0 indicates a normal exit, and 1 indicates an abnormal exit (as long as a non-0 is an exception exit), even if does not pass zero execution can also exit, this parameter only notifies the operating system whether the program is normal exit.

Android Development Two exit program mode (KILLPROCESS,SYSTEM.EXIT)

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.