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()