【Android】Popup Window 在 Android Activity无法弹出的问题

来源:互联网 发布:医疗器械网络销售方法 编辑:程序博客网 时间:2024/04/30 10:23

To avoid BadTokenException, you need to defer showing the popup until
after all the lifecycle methods are called (-> activity window is
displayed):

 findViewById(R.id.main_page_layout).post(new Runnable() {   public void run() {     pw.showAtLocation(findViewById(R.id.main_page_layout), Gravity.CENTER, 0, 0);   }});

翻译:

为了避免BadTokenException ,你需要推迟显示弹出,直到所有的生命周期方法被调用后。

注:
这种方法主要是体现了Android中的消息机制,将显示 Popup Window 的事件post到一个队列中,等待直到所有的生命周期方法被调用后执行事件。

原文地址:http://stackoverflow.com/questions/4187673/problems-creating-a-popup-window-in-android-activity

1 0
原创粉丝点击