public class BaseContext extends Application {
private static Context mContext;
public void onCreate() {
super.onCreate();
mContext = getApplicationContext();
}
public static Context getContext(){
return mContext;
}
最后在清单文件的Application中加入一个name属性:
例如:
android:name=".utils.BaseContext"
在需要调用的方法写:
BaseContext.getContext()