【发布时间】:2018-06-29 10:13:37
【问题描述】:
我的主要活动调用了第二个活动。第二个活动调用了一个 viewholder java 类,从中调用了一个警报对话框:
Log.w(LOG_TAG, "call the alertdialog");
showAlertDialog();
public void showAlertDialog() {
/** define onClickListener for dialog */
DialogInterface.OnClickListener listener
= new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do some stuff eg: context.onCreate(super)
}
};
/** create builder for dialog */
AlertDialog.Builder builder = new AlertDialog.Builder(NFLActivity.context)
.setCancelable(false)
.setMessage("You have made all bets. Select OK to submit...")
.setTitle("All Bets Are In")
.setNegativeButton("Return", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
应用程序因此崩溃: 06-29 10:03:31.340 3740-3740/com.bab_c.picksandbets E/AndroidRuntime: 致命例外: main 进程:com.bab_c.picksandbets,PID:3740 android.view.WindowManager$BadTokenException: 无法添加窗口--token null 无效;您的活动正在进行吗?
我研究发现对话框需要一个活动,但是当使用第二个活动时 showAlertDialog(SecondActivity.context) 仍然失败。
【问题讨论】:
-
如果对话框正在显示,请在关闭活动之前关闭对话框
标签: java android android-activity android-alertdialog