Android实现widget定时更新
2010-06-19 17:37:00 来源:WEB开发网int appWidgetId=getNextWidgetId();
List
if (listNews != null) {
updateViews = NewsWidgetProvider.updateAppWidget(this, listNews);
}
if (updateViews != null) {
appWidgetManager.updateAppWidget(appWidgetId, updateViews);
}
}
Intent updateIntent=new Intent(ACTION_UPDATE_ALL);
updateIntent.setClass(this, NewsService.class);
PendingIntent pending=PendingIntent.getService(this, 0, updateIntent, 0);
Time time = new Time();
long nowMillis = System.currentTimeMillis();
time.set(nowMillis+Long.parseLong(updateTime));
long updateTimes = time.toMillis(true);
Log.d(TAG, "request next update at "+updateTimes);
AlarmManager alarm=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarm.set(AlarmManager.RTC_WAKEUP, updateTimes, pending);
stopSelf();
}
}
这个只是我的情况,如果大家有不一样的情况,稍微修改即可。
赞助商链接