0

我想知道使用IntentService类而不是Serviceandroid小部件中的类来管理UI更新(和注册onClickListener)是否有任何区别。下面是我分别使用的onHandleIntent代码onStartCommand

AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this.getApplicationContext());

int[] allWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);

for (int widgetId : allWidgetIds) {onClickListener

    RemoteViews remoteViews = new RemoteViews(this.getApplicationContext().getPackageName(), R.layout.main);

    // Register an onClickListener
    Intent clickIntent = myIntent(this.getApplicationContext());

    PendingIntent pendingIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.text, pendingIntent);

    appWidgetManager.updateAppWidget(widgetId, remoteViews);

}
4

1 回答 1

0

顺便说一句,如果您想在服务调用期间更新 UI 线程,这是不可能的。但是 Android 提供了 AsyncTasks 来处理这种情况。 http://developer.android.com/reference/android/os/AsyncTask.html

于 2013-06-10T13:02:47.217 回答