我收到以下异常:
Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
at android.view.ViewRootImpl.setView(ViewRootImpl.java:566) ~[na:0.0]
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:272) ~[na:0.0]
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69) ~[na:0.0]
at android.app.Dialog.show(Dialog.java:298) ~[na:0.0]
at kujo.app.ui.VerificationCallingDeviceActivity$2.showDialogIfNotShowing(VerificationCallingDeviceActivity.java:162) ~[na:0.0]
at kujo.app.ui.VerificationCallingDeviceActivity$2.trySigningIn(VerificationCallingDeviceActivity.java:179) ~[na:0.0]
at kujo.app.ui.VerificationCallingDeviceActivity$2.onReceiveCalled(VerificationCallingDeviceActivity.java:220) ~[na:0.0]
at kujo.app.ui.IncomingCall.fireListeners(IncomingCall.java:54) ~[na:0.0]
at kujo.app.ui.IncomingCall.onReceive(IncomingCall.java:79) ~[na:0.0]
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:861) ~[na:0.0]
这发生在调用ProgressDialog.show()函数的行。
我创建了ProgressDialog,如:
new ProgressDialog(VoipApplication.getInstance().getApplicationContext());
其中VoipApplication是一个扩展Application的类。
在某些帖子中,我读到ProgressDialog必须用于Activity。 否则会出现此错误。 有没有其他方法我可以尝试使用ProgressDialog。
答案 0 :(得分:0)
如果您想通知用户正在进行的事情,请使用通知,例如Play商店。
答案 1 :(得分:0)
您也可以尝试
new ProgressDialog(MainActivity.this);
或
new ProgressDialog("Class_name that extends Application".getInstance().getApplication());