Android实现widget定时更新
2010-06-19 17:37:00 来源:WEB开发网return null;
}
public static void updateAppWidgetIds(int[] appWidgetIds){
synchronized (sLock) {
for (int appWidgetId : appWidgetIds) {
sAppWidgetIds.add(appWidgetId);
}
}
}
public static int getNextWidgetId(){
synchronized (sLock) {
if (sAppWidgetIds.peek() == null) {
return AppWidgetManager.INVALID_APPWIDGET_ID;
} else {
return sAppWidgetIds.poll();
}
}
}
private static boolean hasMoreUpdates() {
synchronized (sLock) {
boolean hasMore = !sAppWidgetIds.isEmpty();
if (!hasMore) {
sThreadRunning = false;
}
return hasMore;
}
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
if (null != intent) {
if (ACTION_UPDATE_ALL.equals(intent.getAction())) {
AppWidgetManager widget = AppWidgetManager.getInstance(this);
updateAppWidgetIds(widget.getAppWidgetIds(new ComponentName(this, NewsWidgetProvider.class)));
}
}
synchronized (sLock) {
if (!sThreadRunning) {
sThreadRunning=true;
new Thread(this).start();
}
}
}
@Override
public void run() {
SharedPreferences setting=getSharedPreferences("com.xxxx.news_preferences", 0);
String updateTime=setting.getString("list_time", "1800000");
String updateUrl=setting.getString("list_site", "xxxxxxxxx");
AppWidgetManager appWidgetManager=AppWidgetManager.getInstance(this);
RemoteViews updateViews=null;
while (hasMoreUpdates()) {
赞助商链接