我在下面有一个错误:
//TODO tryAgain
private void tryAgain(){
new AlertDialog.Builder(this)
.setTitle("Game Over")
.setMessage("Times Up!")
.setPositiveButton("Try Again?", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
Intent retry = getIntent();
finish();
startActivity(retry);
}
})
.setNegativeButton("Back to Menu", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
Intent i = new Intent(Stage1_3.this, ShapingColors.class);
finish();
startActivity(i);
}
})
.show();
}
基本上我想要做的是取消对话框然后重新启动我当前的活动和另一个我想回到菜单活动。我在这里缺少什么?任何帮助表示赞赏。
更新日志:
04-27 00:42:44.680: E/AndroidRuntime(330): FATAL EXCEPTION: main
04-27 00:42:44.680: E/AndroidRuntime(330): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@40515dc0 is not valid; is your activity running?
04-27 00:42:44.680: E/AndroidRuntime(330): at android.view.ViewRoot.setView(ViewRoot.java:527)
04-27 00:42:44.680: E/AndroidRuntime(330): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
04-27 00:42:44.680: E/AndroidRuntime(330): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
04-27 00:42:44.680: E/AndroidRuntime(330): at android.view.Window$LocalWindowManager.addView(Window.java:424)
04-27 00:42:44.680: E/AndroidRuntime(330): at android.app.Dialog.show(Dialog.java:241)
04-27 00:42:44.680: E/AndroidRuntime(330): at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
04-27 00:42:44.680: E/AndroidRuntime(330): at com.say.shapingcolor.Stage1_3.tryAgain(Stage1_3.java:307)
04-27 00:42:44.680: E/AndroidRuntime(330): at com.say.shapingcolor.Stage1_3.access$0(Stage1_3.java:287)
04-27 00:42:44.680: E/AndroidRuntime(330): at com.say.shapingcolor.Stage1_3$MyCount.onFinish(Stage1_3.java:319)
04-27 00:42:44.680: E/AndroidRuntime(330): at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:118)
04-27 00:42:44.680: E/AndroidRuntime(330): at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 00:42:44.680: E/AndroidRuntime(330): at android.os.Looper.loop(Looper.java:123)
04-27 00:42:44.680: E/AndroidRuntime(330): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-27 00:42:44.680: E/AndroidRuntime(330): at java.lang.reflect.Method.invokeNative(Native Method)
04-27 00:42:44.680: E/AndroidRuntime(330): at java.lang.reflect.Method.invoke(Method.java:507)
04-27 00:42:44.680: E/AndroidRuntime(330): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-27 00:42:44.680: E/AndroidRuntime(330): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-27 00:42:44.680: E/AndroidRuntime(330): at dalvik.system.NativeStart.main(Native Method)