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

Android实现widget定时更新

 2010-06-19 17:37:00 来源:WEB开发网   
核心提示:private static Queue sAppWidgetIds=new LinkedList();public static final String ACTION_UPDATE_ALL = "com.xxxx.news.UPDATE_ALL";private static boolean s

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

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

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

Tags:Android 实现 widget

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