[Android Q & A] How does one implement the "exit application" function?

Source: Internet
Author: User

Users who have just switched from desktop application development to mobile phone development are often troubled by this problem. After a user presses the Home key, the application is not "completely exited", but "running in the background ", it still occupies system resources. So many background applications will inevitably slow down the system. Should I provide users with an "Exit menu" or "Exit button" in my application?

I have not found any explanation for this issue in the android development documentation. However, after investigating a lot of information on the Internet, I think the answer is obvious:Do not provide the "exit application" Function.

Although it is not clearly stated in the document, if this is a common function, there should be a simple way to achieve it, but in fact it depends onCode"Exit" an application is not easy. The following two solutions can be used to simulate the exit effect:

Solution 1: Open the System Main Screen to simulate the application exit effect, which is no different from pressing the Home Key.

 
Intent intent =NewIntent (intent. action_main); intent. addcategory (intent. category_home); intent. setflags (intent. flag_activity_new_task); startactivity (intent );

Solution 2: directly kill the current application process. This method is too violent. I found a piece of iOS development document. We strongly recommend that you do not use the process kill method to exit the application. The reason is also applicable to the Android system: in this way, the app crashes.

 
IntPID =Android. OS. process. mypid (); Android. OS. process. killprocess (PID );

In addition, it is recommended that you call system. Exit (0) to exit the application. The actual test shows that this method can only close the current activity or does not work at all.

It can be seen that there is no "exit application" mechanism in the Android system design. When a user presses the Home key or the back key on the application homepage, the application is placed in the background, the system determines when to completely kill the application process. Both Android and IOS have abandoned the concept of "exiting the application". For mobile phone users, they only need to know the concept of "starting the application". The fewer the concepts, the easier it will be.

References:

Quitting an application-is that frowned?
Android-exit application code
How to close/exit an application in Android?
Proper way to exit iPhone application?
How do I programmatically quit my IOS application?

Related Article

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.