gpt4 book ai didi

安卓 : BadTokenException when I want to show a progresssDialog a second time

转载 作者:太空狗 更新时间:2023-10-29 15:49:05 25 4
gpt4 key购买 nike

我有一个我无法解决的问题...

在我的 Activity 中,我实例化了一个这样的类:

MapView mapView = (MapView) findViewById(R.id.mapview);<br/>
myMap = new Map(mapView, this);

构造函数看起来像这样

public Map(MapView mapView, Context context) {
this.context = context;
this.mapView = mapView;
}

我想做的是在这个类的过程中显示一个 progressDialog,所以,在 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();
}

当线程结束时,我做

progressDialog.dismiss();

这行得通!但只有一次......如果我点击后退按钮,并重新打开我的 Activity ,我得到一个 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?

我已经尝试了我找到的所有解决方案,但没有一个有效...甚至使用扩展 AsyncTask 的类。

谢谢你的帮助

最佳答案

正如错误消息告诉您的那样,这是因为您尝试在 Activity 中显示对话框但 Activity 没有运行(已经完成?)。因此,在显示对话框之前,您可能需要确保 Activity 未完成:

public class MyActivity extends Activity {

public void showDialog(Dialog dialog) {
if (!isFinishing()) {
// If activity is not finished, then show this dialog.
dialog.show();
}
}

}

关于安卓 : BadTokenException when I want to show a progresssDialog a second time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5921049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com