Hey guys,

can you give me some hints on how to create that custom intent?

1. I have added this to manifest:

<receiver android:name=".Widgetx" android:label="@string/app_name">
                        <intent-filter>
                                <action 
android:name="android.appwidget.action.APPWIDGET_UPDATE" /
>
                                <action android:name="go.updatewidget" />
                        </intent-filter>
                        <meta-data android:name="android.appwidget.provider"
android:resource="@xml/widgetx_provider" />
</receiver>

2. Edited the onReceive in widget code as Evan suggested. However, all
my update logic is in onupdate (so i dont have to implement the if-
clause in onreceive at all, right? the updateappwidget should
suffice..?)
3. I add this to my view:

Intent i = new Intent("go.updatewidget");
sendBroadcast(i);

For some reason nothing happens. The widget just sits there looking at
me :-p

Any ideas, guys?
thx

On Nov 4, 11:02 pm, Evan Ruff <[email protected]> wrote:
> I don't know if this is EXACTLY kosher, but I've overriden the
> onRecieve method in my AppWidgetProvider to look like:
>
> @Override
> public void onReceive( Context context, Intent intent )
> {
>     this.view = new RemoteViews( context.getPackageName(),
> R.layout.widget );
>     if (intent.getAction().equals( MY_AWESOME_CUSTOM_INTENT ))
>     {
>         // DO AWESOME STUFF HERE
>     }
>     else
>     {
>         super.onReceive( context, intent );
>     }
>
>     ComponentName me = new ComponentName( context, VAWidget.class );
>     AppWidgetManager.getInstance( context ).updateAppWidget( me,
> view );
>
> }
>
> Then I just add the custom intents to the widget's intent-filter in
> the manifest as usual.
>
> It has worked every time for me, but I'm wondering if there is a
> scenario where it would not be preferable to do it this way?
>
> E
>
> On Nov 4, 1:11 pm, skink <[email protected]> wrote:
>
> > Mark Murphy wrote:
> > > skink wrote:
> > > > hi,
>
> > > > my custom AppWidgetProvider has onUpdate method where i have logic to
> > > > update RemoteViews
>
> > > > it is not periodically updated by system, but rather, i'd like to
> > > > trigger onUpdate if something happens (in one of my app Activities).
> > > > both custom AppWidgetProvider and Activities i'd like to trigger
> > > > update from run with the same UID
>
> > > > i tried some AppWidgetManager's methods, but no luck, finally i ended
> > > > with really weird solution: i'm sending broadcast with action
> > > > ACTION_APPWIDGET_UPDATE and extras EXTRA_APPWIDGET_IDS which i got
> > > > from AppWidgetManager
>
> > > > is it a common way of updating AppWidgetProvider?
>
> > > You could also just send a broadcast to the provider directly, via the
> > > component-name version of the Intent constructor. Look for a null
> > > action, or some extra you package in, or something to tell it is your
> > > own custom Intent, then do the update work.
>
> > thank you Mark,
>
> > this is exactly what i'm doing now - sending broadcast directly to my
> > AppWidgetProvider by manually creating proper Intent and adding some
> > EXTRA_APPWIDGET_IDS extras
>
> > yet my impression was that this is not the way one should do: i mean i
> > thought there must be some higher level helper method to update
> > AppWidgetProvider
>
> > pskink
>
>

-- 
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