Yet more answering of my own question. ;o)

It turns out that my major stumbling block was not realising that my
AppWidget could actually be just another component of my main
application. I had assumed it had to be a separate application in its
own right, as that was how all the example AppWidget manifests were
set up.

But this is not the case, the AppWidget can be part of the main
application package. It sits quite happily with the rest of the
Activities in my main application's manifest, as long as the
AppWidgets receiver xml is placed inside the application tags, e.g.

<application>
// ......main activities etc.
...
         <receiver android:name=".MyWidget" android:label="My Widget">
        <intent-filter>
                <action
android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
        android:resource="@xml/my_widget_provider" />
          </receiver>
   </application>

It then can use the same application name and icon in the appwidget
home screen picker, and of course can have access to any data my main
application has access to, so there is no need for me to write a
separate content provider.

Hope this helps someone else along the way..



On May 4, 12:41 pm, James W <jpbwebs...@gmail.com> wrote:
> 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 <jpbwebs...@gmail.com> wrote:
>
>
>
>
>
> > I have anAppWidgetwhich provides a summary of some data stored and
> > controlled by my main Application.
>
> > (In a similar way to a CalendarAppWidgetshowing 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 myAppwidget
> > 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 myAppWidgetis 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 android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > 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 android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://groups.google.com/group/android-developers?hl=en- Hide quoted text -
>
> - Show quoted text -

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

Reply via email to