今天在改上一篇中的bug(android.support.v4.app.Fragment$InstantiationException)时又发现了一个问题,经过实验得出结果.
Fragment中获取Activity的Context时只需要this.getActivity()即可.
而不是许多人说的this.getActivity().getApplicationContext(),如果用后者传入AlterDialog肯定会报错(android.view. Window Manager$Bad Token Exception: Unable to add window -- token null is not for an application ).
因为只有activity才可以再开新的窗口.
Fragment中获取Activity的Context时只需要this.getActivity()即可.
而不是许多人说的this.getActivity().getApplicationContext(),如果用后者传入AlterDialog肯定会报错(android.view. Window Manager$Bad Token Exception: Unable to add window -- token null is not for an application ).
因为只有activity才可以再开新的窗口.