I think String is right about that. I wouldn't do that either just to
save battery life!

However I think it is better to set the update interval of the applet
to a high enough amount of time (like 24 hours or sth) and just update
the widget manually. I'm currently working on a widget to and in my
case the widget only receives an update upon clicking a certain
button.

The way I do that is like this:

RemoteViews rv = new RemoteViews(context.getPackageName(), WIDGET);
rv.setTextViewText(R.id.textField, "Updated value for some text on the
widget");
ComponentName cn = new ComponentName(context, YourActivity.class);
AppWidgetManager mgr = AppWidgetManager.getInstance(context);
mgr.updateAppWidget(cn, rv);

That should basically work to update a widget.
Oh and one tip: using the this method you should do all updating just
after the line "rv.setTextViewText(...)". If you execute this entire
block a few times after each other you can get into troubles when
updating the widget.

Dirk

On 28 mei, 23:40, String <sterling.ud...@gmail.com> wrote:
> Before you get too far into this, you need to be aware that the widget
> architecture isn't designed to update that frequently. There's a lot
> of overhead, and updating every ten seconds will seriously impact
> battery life. As will having a service continually running in the
> background, for that matter.
>
> It's a cool idea but I'm not sure it's well suited for a widget,
> unfortunately.
>
> String
>
> On May 28, 2:43 pm, "draf...@gmail.com" <draf...@gmail.com> wrote:
>
>
>
> > I am currently learning about widgets in Android.
>
> > I want to create a WIFI widget that will display the SSID, the RSSI
> > (Signal) level.
>
> > But I also want to be able to send it data from a service I am running
> > that calculates the Quality of Sound over wifi.
>
> > Here is what I have after some reading and a quick tutorial:
>
> > ---
>
> >     public class WlanWidget extends AppWidgetProvider{
>
> >         RemoteViews remoteViews;
> >         AppWidgetManager appWidgetManager;
> >         ComponentName thisWidget;
> >         WifiManager wifiManager;
>
> >         public void onUpdate(Context context, AppWidgetManager
> > appWidgetManager,
> >                         int[] appWidgetIds) {
> >                         Timer timer = new Timer();
> >                         timer.scheduleAtFixedRate(new WlanTimer(context, 
> > appWidgetManager),
> > 1, 10000);
>
> >         }
>
> >         private class WlanTimer extends TimerTask{
>
> >                         RemoteViews remoteViews;
> >                         AppWidgetManager appWidgetManager;
> >                         ComponentName thisWidget;
>
> >         public WlanTimer(Context context, AppWidgetManager appWidgetManager)
> > {
>
> >                         this.appWidgetManager = appWidgetManager;
> >                         remoteViews = new 
> > RemoteViews(context.getPackageName(),
> > R.layout.widget);
> >                         thisWidget = new ComponentName(context, 
> > WlanWidget.class);
> >                         wifiManager =
> > (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
>
> >         }
>
> >         @Override
> >         public void run() {
>
> >                         remoteViews.setTextViewText(R.id.widget_textview,
> >                         wifiManager.getConnectionInfo().getSSID());
> >                         appWidgetManager.updateAppWidget(thisWidget, 
> > remoteViews);
> >         }
>
> >         }
>
> > ---
>
> > The above seems to work ok, it updates the SSID on the widget every 10
> > seconds.
>
> > However what is the most efficent way to get the information from my
> > service that will be already running to update periodically on my
> > widget?
>
> > Also is there a better approach to updating the the widget rather than
> > using a timer and timertask? (Avoid polling)

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