Android Perfect Exit app.

Source: Internet
Author: User

Http://www.2cto.com/kf/201402/276808.html

Android program when clicking the fallback button, if there is only one activity, call the finish () method can exit the interface, if there are multiple interfaces, when invoking the method, will only destroy the current activity, showing the top of the stack other activity, in other words, Is that you cannot exit the entire application. The following is a quick way to exit the entire application code:

private void Showtips () {Alertdialog alertdialog = new Alertdialog.builder (this). Settitle ("Reminder"). s Etmessage ("Whether to quit the program"). Setpositivebutton ("OK", new Dialoginterface.onclicklistener () {PU Blic void OnClick (dialoginterface dialog, int which) {Intent Intent = new Intent (intent.action_mai                          N);                          Intent.addcategory (Intent.category_home);                          Intent.setflags (Intent.flag_activity_clear_top);                      StartActivity (Intent);                    Android.os.Process.killProcess (Android.os.Process.myPid ()); }}). Setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {PU                    Blic void OnClick (dialoginterface dialog, int which) {return; }}). Create (); Create dialog box Alertdialog.show (); Show dialog box

  

@Override Public    boolean onKeyDown (int keycode, keyevent event) {        //TODO auto-generated method Stub        if (KEYC Ode = = Keyevent.keycode_back && event.getrepeatcount () = = 0) {            showtips ();            return false;        }         Return Super.onkeydown (KeyCode, event);    }

  

Android Perfect Exit app.

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.