问题描述
我有解决不了的问题...
I have a problem that I can't solve...
在我的活动,我实例化一个类是这样的:
In my Activity, I instantiate a class like this :
MapView类MapView类=(图形页面)findViewById(R.id.mapview);结果
MYMAP =新地图(图形页面,这一点);
构造看起来像这样
public Map(MapView mapView, Context context) {
this.context = context;
this.mapView = mapView;
}
和我想要做的就是在这个类的一个过程来显示progressDialog,所以,在地图,我得到了
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();
}
当线程结束后,我
progressDialog.dismiss();
这个作品!但只有一次......如果我点击后退按钮,并重新打开我的活动,我得到了BadTokenException
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:无法添加窗口 - 令牌android.os.BinderProxy@44ecc8e8无效;是您的活动运行?
我tryed所有的解决方案,我发现,但没有人的作品......甚至用谁延伸AsyncTask的一类。
I've tryed all solutions I found, but no one works... Even use a class who extends AsyncTask.
感谢您的帮助。
推荐答案
至于什么错误信息告诉你,那是因为你试图说明在活动对话框但活动没有运行(已经做完了吗?)。所以你看一个对话框之前,您可能希望确保活动还未结束:
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:
public class MyActivity extends Activity {
public void showDialog(Dialog dialog) {
if (!isFinishing()) {
// If activity is not finished, then show this dialog.
dialog.show();
}
}
}
这篇关于安卓:BadTokenException时,我想表现出progresssDialog第二次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!