我想知道使用IntentService
类而不是Service
android小部件中的类来管理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);
}