无法理解该堆栈跟踪
问题描述:
我有一个发布的应用程式,并收到了来自崩溃堆栈跟踪:无法理解该堆栈跟踪
android.view.WindowManager$BadTokenException: Unable to add window -- token
[email protected] is not valid; is your activity running?
at android.view.ViewRoot.setView(ViewRoot.java:535)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:203)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:117)
at android.view.Window$LocalWindowManager.addView(Window.java:424)
at android.app.Dialog.show(Dialog.java:241)
at android.app.ProgressDialog.show(ProgressDialog.java:107)
at android.app.ProgressDialog.show(ProgressDialog.java:90)
at com.mytaxicontrol.MyTaxiControlActivity$executeGEO.void onPreExecute()(Unknown Source)
at android.os.AsyncTask.execute(AsyncTask.java:391)
at com.mytaxicontrol.MyTaxiControlActivity$37.void run()(Unknown Source)
at android.app.Activity.runOnUiThread(Activity.java:3743)
at com.mytaxicontrol.MyTaxiControlActivity.void geo()(Unknown Source)
貌似对话框不能显示进度。下面是相关的代码:
public void onPreExecute() {
if(isGeoRunning)return;
if (loading == null || !loading.isShowing())
loading = ProgressDialog.show(co, "",
"Retrieving Geolocation...", true);
}
注意,CO =这个和的onCreate() 什么是我的问题已经初始化?
答
这可能是用户在您的Asynctask完成之前“BACK”。
答
android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌
[email protected]无效;你的活动正在运行?
您的应用程序可能是刚刚重新创建,因为屏幕旋转或用户按Home/Back或类似的事情发生。所以你的应用程序实际上没有运行。
让UI + AsyncTasks不会破坏活动生命周期,但有一些选项有点棘手。
例如为: http://groups.google.com/group/android-developers/browse_thread/thread/e1d5b8f8a3142892
基本上你需要确保的AsyncTask不触及UI虽然没有UI。
我可以对此做任何事吗? – michaelsmith 2012-03-14 19:18:28
是的,在尝试添加窗口之前检查活动是否为空,或者在 – 2012-03-14 19:18:59
周围添加一个try ... catch块,这发生在我的主要活动中,所以我应该这样做:if(co!= null)... – michaelsmith 2012-03-14 19:20:07