当按下按钮时,我有一个“alertDialogBuilder”来重命名条目。当应用程序刚打开时,这可以正常工作。但是如果我按下返回按钮(意味着应用程序被最小化并且我回到 Android 主屏幕),当我重新启动应用程序并按下按钮时,这一次应用程序崩溃了。每次都会发生这种情况,我不知道如何调试它。我检查了生命周期,按下后退按钮时会调用“onPause”和“onStop”。但我不明白为什么这应该是一个问题。
有任何想法吗?
这是我在助手类中启动提示对话框的代码:
public void loadPromptInput(Context promptcontext, final OnOkGetText onOk, String InitialTxt) {
//pathText.setText("Prompt input");
LayoutInflater li = LayoutInflater.from(promptcontext);
View promptsView = li.inflate(R.layout.prompts_dialog, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( promptcontext);
// set prompts.xml to alertdialog builder
alertDialogBuilder.setView(promptsView);
final EditText userInput = (EditText) promptsView
.findViewById(R.id.editTextDialogUserInput);
userInput.setText("");
userInput.append(InitialTxt);
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
onOk.hereIsYouText(userInput.getText().toString());
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
// make the keyboard shown by default
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
E/AndroidRuntime: FATAL EXCEPTION: main Process: com...., PID: 31622 android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@423c9940 is not valid; 您的活动正在运行吗?在 android.view.ViewRootImpl.setView(ViewRootImpl.java:532) 在 android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:259) 在 android.view.WindowManagerImpl.addView(WindowManagerImpl.java:
od)