Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can getContentResolver() be called in Android?

Tags:

android

I want to know the context in which getContentResolver() is called?

I have a scenario like this:
I have an activity A that calls a method myFunc() of class B which is not an activity.
So, in class B I have to use getContentResolver(). I directly called getContentResolver(). It was showing error. Then I called myFunc(Acitivy act) from the activity and called act.getContentResolver() which solved my problem. Is this the only way to call getContentResolver(), which means it can be used in context with activity or can be used alone.

like image 239
Android_programmer_office Avatar asked Sep 20 '10 11:09

Android_programmer_office


People also ask

What is the use of getContentResolver ()?

They enable you to decouple your application layers from the underlying data layers, making your application data-source agnostic by abstracting the underlying data source. Show activity on this post.

What is the content resolver?

What is the Content Resolver? The Content Resolver is the single, global instance in your application that provides access to your (and other applications') content providers.


2 Answers

getContentResolver() is method of class android.content.Context, so to call it you definitely need an instance of Context ( Activity or Service for example).

like image 97
Nikolay Ivanov Avatar answered Sep 21 '22 04:09

Nikolay Ivanov


You can use like this:

getApplicationContext().getContentResolver() 

with the proper context.

like image 42
Ankit Jain Avatar answered Sep 24 '22 04:09

Ankit Jain