开发学院手机开发Android 开发 Android实现widget定时更新 阅读

Android实现widget定时更新

 2010-06-19 17:37:00 来源:WEB开发网   
核心提示:SharedPreferences setting=getSharedPreferences("com.xxxx.news_preferences", 0);String updateTime=setting.getString("list_time", "180000

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()) {

int appWidgetId=getNextWidgetId();

List listNews = NewsContenttList.getNewsList(updateUrl);

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();

}

}

public class NewsService extends Service implements Runnable {

private static final String TAG="NewsService";

private static Queue sAppWidgetIds=new LinkedList();

public static final String ACTION_UPDATE_ALL = "com.xxxx.news.UPDATE_ALL";

private static boolean sThreadRunning = false;

private static Object sLock = new Object();

@Override

public IBinder onBind(Intent intent) {

上一页  1 2 3 4 5 6  下一页

Tags:Android 实现 widget

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接