//在Android的清单文件做如下申明:
<application android:name="com.xyz.MyApplication">
</application>
//然后写这个类:
public class MyApplication extends Application{
private static Context context;
public void onCreate(){
super.onCreate();
MyApplication.context = getApplicationContext();
}
public static Context getAppContext() {
return MyApplication.context;
}
}
//调用MyApplication.getAppContext()来静态的获取你应用程序的context。
版权声明:本文为博主原创文章,未经博主允许不得转载。