2013年8月2日 星期五

[ Android ] : Static Way to get Context



public class MyApplication extends Application{

    private static Context context;

    public void onCreate(){
        super.onCreate();
        MyApplication.context = getApplicationContext();
    }

    public static Context getAppContext() {
        return MyApplication.context;
    }

}

then just call  MyApplication.getAppContext(); to get context


沒有留言: