Making getContentResolver() to work in class extending Fragment class
Try to add this code to a previous activity:
// a static variable to get a reference of our application contextpublic static Context contextOfApplication;public static Context getContextOfApplication(){return contextOfApplication;}
and in the same activity, in your onCreate method add this line:
contextOfApplication = getApplicationContext();
In your fragment you can access this by using :
Context applicationContext = YourActivity.getContextOfApplication();applicationContext.getContentResolver();
Getting the application context using getter doesn't work. The equivalent of above answer is
getActivity().getApplicationContext().getContentResolver().
When using android.support.v4.app.Fragment
:
getActivity().getContentResolver()