I have a terrible bug in my widget.  The widget is waken up using an
AlarmManager (the update interval is chosen by users, ranging from 30
mins to 2 hours) to grab some data from the Internet and display it on
the widget.  I do not hold a wakelock since if the phone sleeps, just
let it sleeps.  There's no way to update the information since nobody
will see it.
If I put the phone in the basement (has no wi-fi or cell signal) for
about an hour. the phone will definitely not update anything.
However, when I get it back from the basement, the cell network could
never be recovered again no matter how long I have waited (it just get
an X on the cell signal icon on the notification bar) that I must
restart the phone.  May I know if a partial wake lock must be held on
checking network availability?

Your help is highly appreciated.  Please find the code skeleton as
below:

        public void onReceive(Context context, Intent intent) {
                ......
                Intent intent = new Intent(context, UpdateAppWidget.class);
                context.startService(intent);
                ......
        }

        public static class UpdateAppWidget extends Service {
                @Override
                public void onStart(Intent intent, int startId) {
                        ......
                        ConnectivityManager cm =  (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
                        if
(cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isAvailable() ||
                                
cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isAvailable()) {
                                ......Grab something in the net.......
                        }

                        ......
                        //  Make another alarm for next update
                        Intent widgetUpdate = new Intent();
                        
widgetUpdate.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                        
widgetUpdate.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new
int[]{widgetId});
                        
widgetUpdate.setData(Uri.withAppendedPath(Uri.parse(URI_HEADER),
String.valueOf(widgetId)));
                        PendingIntent newPending = 
PendingIntent.getBroadcast(this, 0,
widgetUpdate, pendingIntent.FLAG_UPDATE_CURRENT);
                        AlarmManager alarm = (AlarmManager)
this.getSystemService(Context.ALARM_SERVICE);
                                        alarm.set(AlarmManager.RTC, 
System.currentTimeMillis() + 1000 *
currentValue, newPending);

                        //  Refresh the widget
                        manager.updateAppWidget(widgetId, views);

                        //  Kill the service after done
                        this.stopSelf();
                }
        }

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

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to