Android2.3 禁止系统强制关闭对话框

来源:互联网 发布:python金融大数据 pdf 编辑:程序博客网 时间:2024/05/18 02:13

当应用程序出错的时候,系统会弹出强制关闭的对话框,这样不够友好,可以学习水果的做法,直接干掉程序。

弹出出错的对话框路径:

frameworks/base/services/java/com/android/server/am/AppErrorDialog.java

在第38、39行有以下语句:

    // 5-minute timeout, then we automatically dismiss the crash dialog
    static final long DISMISS_TIMEOUT = 1000 * 60 * 5;

  这个是在强制退出对话框弹出时,如果用户没有点击Force  close按钮,五分钟后这个对话框自动消失。


弹出对话框的处理:

 frameworks/base/services/java/com/android/server/am/ActivityManagerService.java: 在980行附件有弹出对话框的处理:

                   if (!mSleeping && !mShuttingDown) {
                        Dialog d = new AppErrorDialog(mContext, res, proc);
                        d.show();
                        proc.crashDialog = d;
                    } else {
                        // The device is asleep, so just pretend that the user
                        // saw a crash dialog and hit "force quit".
                        res.set(0);
                    }

可以直接将这些语句改为:  res.set(0);

这样程序再出错就直接退出,不会提示强制退出对话框了。


原创粉丝点击