我有一个无法解决的问题…
在我的活动中,我实例化了这样一个类:
MapView mapView = (MapView) findViewById(R.id.mapview);
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();
这能行!但只有一次…如果我单击back按钮,然后重新打开我的活动,就会出现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的类。
谢谢你的帮助

最佳答案

正如错误消息告诉您的,这是因为您试图在活动中显示一个对话框,但该活动未在运行(已完成?)。因此,在显示对话框之前,可能需要确保活动未完成:

public class MyActivity extends Activity {

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

}

10-07 19:32
查看更多