Ok, I can partially answer my own question, in between posting and
getting past the moderators, I worked out that I need a Context to
call getContentResolver(), and whilst the AppWidgetProvider is not
derived from Context, a Context is passed through to all the
AppWidgetProvider calls such as onUpdate().

My other question still stands, is a ContentProvider the best way to
get the data from my main app? I should point out that I need at most
3 numbers to be retreived which are quickly and simply calculated by
my main app, so it is unlikely that there will be a ANR involved.
Hence it seemed a direct call to the app's ContentProvider was more
appropriate than launching another thread for a service?


On Apr 30, 6:32 pm, James W <[email protected]> wrote:
> I have an AppWidget which provides a summary of some data stored and
> controlled by my main Application.
>
> (In a similar way to a Calendar AppWidget showing the next event from
> the main Calendar application).
>
> I want to know the best practice for retrieving the data to update my
> widget.
>
> I have followed the example, and I have extended AppWidgetProvider and
> have a working widget, onto which I can update.
>
> I would expect to read the data from my main application and then
> update it via my AppWidgetProvider's onUpdate() routine.
>
> Now, is the best practice here for my separate main application to
> provide the data via a ContentProvider? I assume so, as my Appwidget
> is not part of the same application.
>
> Is it possible to access a ContentProvider inside my onUpdate()
> routine?
>
> Before writing my main application content provider I started to test
> out retrieving some available data like Contacts information, and
> showing say a contact name in my widget, to show I can extract data
> from an existing ContentProvider.
>
> When accessing the Contacts contentprovider, the examples talk
> about:
>
> 1) Activity.managedQuery(), but my AppWidget is not an activity.
> 2) ContentResolver.query(), but I can't work out how to get a valid
> ContentResolver so I can access the Contacts.
>
> getContentResolver() does not appear to be defined for
> AppWidgetProviders.
>
> Am I approaching this the correct way?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to