Android exits app

Source: Internet
Author: User

Put the activity instance in a linear container in oncreate (). When you exit (activity) List. GERT (I). finsh ();

There are also obvious problems...

The reference of the activity is saved, whether it will be involved, and the memory is recycled .... (You have to use the following method for strong reference .)

Package COM. mystore. customer. activity; import Java. io. printwriter; import Java. io. stringwriter; import Java. io. writer; import Java. lang. thread. uncaughtexceptionhandler; import Java. util. using list; import Java. util. list; import mylog. log; import android. app. activity; import android. app. application; import android. content. PM. packagemanager. namenotfoundexception; import COM. mystore. customer. activity. lookfor. loo Kforcustomeractivity; import COM. mystore. customer. activity. more. moremessageactivity; import COM. mystore. customer. activity. ramble. hotstoreactivity; import COM. mystore. customer. activity. search. searchmainactivity; public class customerapplication extends application {Private Static final string tag = "customerapplication"; Private Static application; public static string version = "1.1"; Public Static long exit_timeout = 2500l; // Add activity container, used to exit app private list <activity> activitylist = new sort list <activity> (); Private Static customerapplication instance; // obtain the unique exitapplication instance public static customerapplication getinstance () {If (null = instance) {instance = new customerapplication ();} return instance;} in singleton Mode ;} // Add the activity to the container public void addactivity (activity activi Ty) {activitylist. add (activity);} // traverse all activities and finishpublic void exit () {for (activity: activitylist) {activity. finish ();} system. exit (0);} public void poptomaintab () {for (INT I = activitylist. size ()-1; I> 0; I --) {activity = activitylist. get (I); If (activity! = NULL) {If (hotstoreactivity. class ). equals (activity. getclass () | (mainactivity. class ). equals (activity. getclass () | (searchmainactivity. class ). equals (activity. getclass () | (moremessageactivity. class ). equals (activity. getclass () | (lookforcustomeractivity. class ). equals (activity. getclass () {// jump out of loop break;} else {activity. finish () ;}}@ overridepublic void oncreate () {super. oncreate (); thread. partition (new partition () {public void uncaughtexception (thread, throwable) {final writer result = new stringwriter (); Final printwriter = new printwriter (result); throwable. printstacktrace (printwriter); string strstacktrace = result. tostring (); printwriter. close (); log. E ("", "================================"); log. E ("", "force close occur, thread is:" + thread + "throwable:" + throwable); log. E ("", "stacktrace" + strstacktrace); log. E ("", "================================ ");}}); application = This; try {version = This. getpackagemanager (). getpackageinfo (this. getpackagename (), 0 ). versionname;} catch (namenotfoundexception e) {e. printstacktrace () ;}} public static application getapplication () {return application ;}}

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.