如何在Fragment中获取Activity

来源:互联网 发布:什么是数据库架构师 编辑:程序博客网 时间:2024/05/17 04:58
Fragment中获取Activity的Context时只需要this.getActivity()即可.
    而不是许多人说的this.getActivity().getApplicationContext(),如果用后者传入AlterDialog肯定会报错(android.view.WindowManager$BadTokenException:Unable to add window -- token null is not for an application).
   因为只有activity才可以再开新的窗口.
0 0