Android Perfect Exit app.

Source: Internet
Author: User

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:

?
1234567891011121314151617181920212223 private void showTips() {          AlertDialog alertDialog = new AlertDialog.Builder(this).setTitle("提醒")                 .setMessage("是否退出程序")                 .setPositiveButton("确定", new DialogInterface.OnClickListener() {                       public void onClick(DialogInterface dialog, int which) {                         Intent intent = new Intent(Intent.ACTION_MAIN);                           intent.addCategory(Intent.CATEGORY_HOME);                           intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);                           startActivity(intent);                       android.os.Process.killProcess(android.os.Process.myPid());                     }                  }).setNegativeButton("取消",                   new DialogInterface.OnClickListener() {                     public void onClick(DialogInterface dialog, int which) {                         return;                     }                 }).create(); // 创建对话框         alertDialog.show(); // 显示对话框     }
?
12345678910 @Override    public boolean onKeyDown(int keyCode, KeyEvent event) {         // TODO Auto-generated method stub         if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {             showTips();             return false;         }          return super.onKeyDown(keyCode, event);     }
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.