Actuellement, je suis en train d'étudier le widget app avec collection, et il y a deux points que je suis confus, voir ci-dessous les codesDeux questions sur widget app avec collection
codes onUpdate
Intent serviceIntent=new Intent(context,StackService.class);
serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));
RemoteViews remoteViews=new RemoteViews(context.getPackageName(),R.layout.stack_widget);
remoteViews.setRemoteAdapter(R.id.stack_widget,serviceIntent);
remoteViews.setEmptyView(R.id.stack_widget,R.id.stack_empty);
Intent toastIntent = new Intent(context, StackWidget.class);
toastIntent.setAction(StackWidget.TOAST_ACTION);
toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
PendingIntent toastPendingIntent = PendingIntent.getBroadcast(context, 0, toastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setPendingIntentTemplate(R.id.stack_widget, toastPendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds[i],remoteViews);
codes getViewAt
public RemoteViews getViewAt(int position) {
RemoteViews remoteViews=new RemoteViews(getPackageName(),R.layout.stack_item);
remoteViews.setImageViewResource(R.id.item_image,R.raw.logo);
remoteViews.setTextViewText(R.id.item_text,list.get(position));
Bundle extras = new Bundle();
extras.putInt(StackWidget.EXTRA_ITEM, position);
Intent fillIntent=new Intent();
fillIntent.putExtras(extras);
remoteViews.setOnClickFillInIntent(R.id.item_button,fillIntent);
return remoteViews;
}
Première question est quel but de code ci-dessous, serviceIntent.setData (Uri.parse (serviceIntent.toUri (Intent .URI_INTENT_SCHEME))); Je lis à travers google api doc, mais ne trouve pas de réponse.
deuxième question est sur le point toastIntent, pourquoi l'action est l'intention d'être fixé à la méthode onUpdate plutôt qu'à la méthode getViewAt? Et pourquoi l'intention en attente qui a une action personnalisée appelée TOAST_ACTION sera déclenchée lorsque le bouton est enfoncé?
Merci d'avoir répondu à mes questions à l'avance.
Pourriez-vous m'expliquer le but de mettre setData ici? – Leon
Non, je ne vous le dirai pas. – user7078144