Android Exit program solves memory release problem _android

Source: Internet
Author: User
When you do an Android project, you find a problem: When the application exits, click "Settings" to view the application, and the interface shows you can click "Force off".

I think the reason for this is that there are still open activity not being destroy, then debugging, and then found that the activity should be all destroy. But the result is that you can click "Force off".

As a result of this problem I found a more serious problem, that is, after my application quit, the system did not release my application memory.

Then look up the solution on the Internet. said there are two:

Mode one:
Intent Intent = new Intent (intent.action_main);
Intent.addcategory (Intent.category_home);
Intent.setflags (Intent.flag_activity_new_task);
This.startactivity (Intent);
System.exit (0);

Mode two:
Android.os.Process.killProcess (Android.os.Process.myPid ());


Some people say that they can end the application, but for some reason, I still can't end my application after trying these two methods.
When I click "Settings" to see my application, the interface still shows that you can click "Force off".
However, these two methods can be used to free up the memory of the application.
Serious problem solved, the problem that can click "forced shutdown" does not seem to have any effect. So I didn't solve the problem.
Finally say the two ways and where to use it.
The first way is to exit the virtual machine, and in this way, it should be noted that if the device has two or more application category for the home
Application, the device lets the user choose which application to go to when exiting the application.
The second way is to kill the current application process. It does not happen to allow the user to choose which application to go into.
Where to use these two methods is generally used in the OnDestroy () method of the last activity
@Override
protected void OnDestroy () {
TODO auto-generated Method Stub
Super.ondestroy ();
Release application ' s RAM
Intent Intent = new Intent (intent.action_main);
Intent.addcategory (Intent.category_home);
Intent.setflags (Intent.flag_activity_new_task);
This.startactivity (Intent);
System.exit (0);
}
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.