jay*_*del 2 android android-studio
当我尝试初始化context使用时getActivity(),Android Studio会显示错误"无法解析符号".如何从活动类中获取上下文?
Lea*_*ess 22
不要用getActivity.使用this.
例如:
Context context = this;
Run Code Online (Sandbox Code Playgroud)
getActivity()如果你在片段里面就被使用了.在活动中,您可以使用this关键字.
顺便说一句,在一个活动中,你不需要使用context,getSharedPreferences()方法已经存在Activity.只需调用getSharedPreferences()方法而无需context参考.
| 归档时间: |
|
| 查看次数: |
26485 次 |
| 最近记录: |