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

android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@45f48c40 is not valid; is your activity running? 今天在写android 的google 地图时遇到一个问题,我在地图上添加一个Overlay 然后想在点击这个overlay 图标的时候弹对话框Dialog, 按这样的思路写完后,测试报出了上面的异常。 代码如下: //这是一个继承了ItemizedOverlay 的类中的方法。 @Override public boolean onTap(int i) { // TODO Auto-generated method stub OverlayItem item = allMapOverlays.get(i); AlertDialog.Builder dialog = new AlertDialog.Builder(context); dialog.setTitle(item.getTitle()); dialog.setMessage(item.getSnippet()); dialog.show(); return true; } 查资料说问题在于 context. 说不能使用 getApplicationContext(),this 所得到的Context 必须用your_Activity.this 所获取的Context. 而我就是用最后一种的,还是出差。 于是我想下我的实际的运行环境,我的地图是在tabActivity 中的,那么得到当前的窗体管理者应该是上一级TabActivity 所有,而非我的地图Activity 于是我 用 getParent()所得到的Context,运行成功。
posted @ 2011-10-19 16:37  青香蕉  阅读(39717)  评论(0编辑  收藏  举报