小编A.B*_*sha的帖子

显示来自 Retrofit 拦截器的对话框

当很少有参数不满足时,我试图从 Retrofit 拦截器显示一个对话框。但是android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?在尝试显示对话框时出现异常。

这是我的代码。

final AlertDialog.Builder alertDialog = new AlertDialog.Builder(ShieldSquare.applicationContext)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setTitle("Are you sure to Exit")
            .setMessage("Exiting will call finish() method")
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            })
            //set negative button
            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    //set what should happen when negative button is clicked
                    Toast.makeText(ShieldSquare.applicationContext,
                            "Nothing Happened", Toast.LENGTH_LONG).show(); …
Run Code Online (Sandbox Code Playgroud)

android dialog interceptor retrofit

3
推荐指数
1
解决办法
1371
查看次数

标签 统计

android ×1

dialog ×1

interceptor ×1

retrofit ×1