Android-全局获取Context
自定义类继承自Application:
//全局获取Context技巧
public class MyApplication extends Application {
private static Context context;
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
}
public static Context getContext() {
return context;
}
}
AndroidManifest.xml文件中指定application name为该类的名字:
调用方法:
MyApplication.getContext();