zoukankan      html  css  js  c++  java
  • 退出整个应用解决方案

    1、配合FLAG_ACTIVITY_CLEAR_TOP使用,但是service不能被杀掉

    private void showTips() {
    
            AlertDialog alertDialog = new AlertDialog.Builder(this).setTitle("提醒").setMessage("是否退出程序")
                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {
    
                        public void onClick(DialogInterface dialog, int which) {
                            //startActivity先清楚之前所有的activity再跳转到主界面
                            Intent intent = new Intent(Intent.ACTION_MAIN);
                            intent.addCategory(Intent.CATEGORY_HOME);
                            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(intent);
                            //杀死当前进程,只能消灭当前Activity
                            android.os.Process.killProcess(android.os.Process.myPid());
                        }
    
                    }).setNegativeButton("取消",
    
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    return;
                                }
                            })
                    .create(); // 创建对话框
            alertDialog.show(); // 显示对话框
        }

    Done

  • 相关阅读:
    hdu 5072 Coprime (容斥)
    洛谷 P1411 树 (树形dp)
    Tr/ee AtCoder
    sys.path
    uname
    sys.platform
    Eclipse Basic
    Eclipse Color Theme
    Pydev
    scons
  • 原文地址:https://www.cnblogs.com/xingyyy/p/5229427.html
Copyright © 2011-2022 走看看