Android アプリケーションが例外をスローしたときに、何か問題が発生したことをユーザーに知らせるカスタム ダイアログを表示したいのでThread.setDefaultUncaughtExceptionHandler、グローバル例外ハンドラーを設定します。
public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread thread, final Throwable ex) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
                builder.setTitle("There is something wrong")
                        .setMessage("Application will exit:" + ex.toString())
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // throw it again
                                throw (RuntimeException) ex;
                            }
                        })
                        .show();
            }
        });
    }
}
しかし、例外がスローされ、AlertDialog表示されず、代わりにアプリケーションがブロックされ、しばらくするとシステム ダイアログが表示されることがわかりました。
X app is not responding. Would you like to close it?
Wait  |  OK
私は今どうすればいい?
アップデート
ログ:
11-16 12:54:16.017: WARN/WindowManager(90): Attempted to add window with non-application token WindowToken{b38bb6a8 token=null}.  Aborting.
エラーが発生しているようですnew AlertDialog.Builder(getApplicationContext());
しかし、これはApplicationサブクラスの例外ハンドラーです。どうすればアクティビティ インスタンスを設定できますか?