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

Source: Internet
Author: User

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

You can open DDMM to see the process number, and 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-2 minutes to push it back.

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

@Override      Public int int 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 after 1-2 minutes the system restarts the service, of course, a new process will be created first, as well as you can see the killing of the process and the rebuilding of the new process in the DDMM.

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 DDMM

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.

my level is limited, there are problems everyone more discussion ....

Interested students can use me to write the demo test: Http://pan.baidu.com/s/1c0xS5g8

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.