android.view.WindowManager$BadTokenException: Unable to add window

错误:

02-23 13:59:20.245: E/AndroidRuntime(30690): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@4054b8f8 is not valid; is your activity running?

TabActivity 里指定了一个 Activity 1,Activity 1 里又包含了另外一个Activity 2, 在  Activity2 里 有以下代码:

dialog = ProgressDialog.show(VehicleMapActivity.this, "", "Connect to server...");

改为以下代码即可:

dialog = ProgressDialog.show(VehicleMapActivity.this.getParent(), "", "Connect to server...");

 考虑一下实际的运行环境,得到当前的窗体管理者应该是上一级 Activity1 所有,而非Activity2, 于是我 用 getParent()所得到的Context,运行成功。

猜你喜欢

转载自sunzeping.iteye.com/blog/1859721