Android Process.killprocess and System.exit (0) differences

Source: Internet
Author: User

Original: http://www.cnblogs.com/lesliefang/p/3933640.html

1 process.killprocess and System.exit (0) Two will kill the current process.

You can open DDMS to see the process number, or the ADB shell enters the shell and PS, the process is actually killed.

2 If the first Activity call process.killprocess or System.exit (0) will kill the current process.

But if it is not called in the first Activity, such as Activitya startup Activityb, you call in Activityb

Process.killprocess or System.exit (0) The current process has actually been killed, but the app will restart,

A new process has also been created. (This was found by my colleague)

This is not very clear, I guess the Android OS think the app was accidentally terminated (such as out of memory), the OS underlying the monitoring service,

The app is automatically restarted when it is terminated unexpectedly.

3 When you test the Aurora push, you will not receive the push when you exit the app. It was later discovered that the reason for System.exit (0) was called.

First the service is also in the process, in the main thread, so if there is a time-consuming operation in the service to open another thread to handle.

When System.exit (0) or process.killprocess is called, the process is killed, and everything in the process includes the service certainly

It's gone. Since the Aurora push Pushservice was killed, the app will not be pushed out.

4 is not over, the dramatic thing happened, just quit the app because kill off the process, the service is gone, so can't receive push. But it took about 1 minutes or so to push it back.

This is related to the return value of the service's Onstartcommand

@Override public    int Onstartcommand (Intent Intent, int flags, int startid) {        log.i ("Lelsie", "service Onstartcommand ");        return start_sticky;        return start_not_sticky;    }

If the return start_sticky is said the service should always run unless we manually stop it. The Aurora Pushservice returned is definitely start_sticky.

So in 1 minutes the system restarts the service, of course, will first create a new process for the app, that is, restart the app, as well as you can see in the DDMM process of killing and new process reconstruction.

I cut 2 pictures on my cell phone.

The first figure is the diagram after the call of Process.killprocess or System.exit (0), and you can see that the process is no longer there, and the service is of course not. The display is restarting.

The second graph is the normal state after the service restarts, so you can receive the push again after 1-2 minutes.

The third figure is DDMS

5 in fact process.killprocess or system.exit (0) should not be called directly, the process is managed by the OS underlying, the Android system will process the recycling itself.

Quit the app and you just finish off the activity.

Normally the back key exits the app and the OS recycles the app, but the OS does not kill the process when it has a long-running service such as a push service in the app, which means the app will always be online. Even if you kill the process manually, the process restarts automatically.

I have a limited level, we have a problem to discuss more ....

Android Process.killprocess and System.exit (0) differences

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.