Android:当我想第二次显示进度对话框时出现 BadTokenException
我有一个无法解决的问题...
在我的 Activity 中,我实例化了一个这样的类:
MapView mapView = (MapView) findViewById(R.id.mapview);
myMap = new Map(mapView, this);
构造函数如下所示
public Map(MapView mapView, Context context) {
this.context = context;
this.mapView = mapView;
}
我想要做的是在此类的过程中显示一个进度对话框,所以,在 Map 中,我得到了
private void showPath() {
progressDialog = ProgressDialog.show(context, "Veuillez patienter", "Calcul de l'itinéraire en cours...", true, false);
Thread thread = new Thread(this);
thread.start();
}
When thread is over, I执行
progressDialog.dismiss();
这有效!但只有一次...如果我单击后退按钮,然后重新打开我的活动,我会得到一个 BadTokenException
05-06 23:27:15.941: ERROR/AndroidRuntime(1247): android.view.WindowManager$ BadTokenException:无法添加窗口 - 令牌 android.os.BinderProxy@44ecc8e8 无效;你的活动正在运行吗?
我已经尝试了我找到的所有解决方案,但没有一个有效...甚至使用扩展 AsyncTask 的类。
感谢您的帮助
I have a problem that I can't solve...
In my Activity, I instantiate a class like this :
MapView mapView = (MapView) findViewById(R.id.mapview);
myMap = new Map(mapView, this);
The constructor looks like this
public Map(MapView mapView, Context context) {
this.context = context;
this.mapView = mapView;
}
And what I want to do is to show a progressDialog during a process of this class, so, in Map, I got
private void showPath() {
progressDialog = ProgressDialog.show(context, "Veuillez patienter", "Calcul de l'itinéraire en cours...", true, false);
Thread thread = new Thread(this);
thread.start();
}
When thread is over, I do
progressDialog.dismiss();
This works ! But only one time... If I click on the back button, and re open my activity, I got a BadTokenException
05-06 23:27:15.941: ERROR/AndroidRuntime(1247): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@44ecc8e8 is not valid; is your activity running?
I've tryed all solutions I found, but no one works... Even use a class who extends AsyncTask.
Thank you for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如错误消息告诉您的那样,这是因为您尝试在活动中显示对话框,但活动没有运行(已经完成?)。因此,在显示对话框之前,您可能需要确保活动尚未完成:
As what the error message told you, it's because you try to show a dialog in a Activity but the Activity is not running(have already been finished?). So before you show a dialog, you may want to make sure that the Activity is not finished: