0
android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@406a6678 is not valid; is your activity running?
at android.view.ViewRoot.setView(ViewRoot.java:528)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at android.view.Window$LocalWindowManager.addView(Window.java:424)
at android.app.Dialog.show(Dialog.java:241)
at android.app.Activity.showDialog(Activity.java:2569)
at android.app.Activity.showDialog(Activity.java:2527)
at MyCode$8$4.run(MyCode.java:557)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)

执行以下代码时出现异常。处理完成且进度条达到 100% 后,将显示此文件对话框。FileSaveDialog 扩展了 Dialog 并实现了 OnCompletionListener

runOnUiThread(new Runnable() {
    @Override
    public void run() {
        showDialog(error.Code());//Line 557
    }
});

    @Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;
    AlertDialog.Builder builder;
    final ScrollView scrollView = new ScrollView(this);
    final TextView textView = new TextView(this);

    switch (id) {
    // Other cases are here
    case 4:
        File playFile = new File(mediaPath, TEMP_WAV_FILE_NAME);

        dialog = new FileSaveDialog(this, getResources(),
                playFile.getAbsolutePath(), saveDiscardHandler);
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                // do whatever you want the back key to do
                cleanUp();
            }
        });

        break;
    // Other cases are here
    default:
        dialog = null;
    }
    return dialog;
}
4

1 回答 1

1

您必须检查活动isFinishing()如果活动正在完成,则返回 true;否则返回假。

于 2013-10-08T06:25:31.677 回答