Hi there
I got a Widget on my HomeScreen on which i add an click to a Button. I pass the widget id from the Widget to a Service, but when im reading the WidgetId at the Service it's always 3.
Widget:
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
for (int appWidgetId : appWidgetIds) {
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget);
Intent intent = new Intent(context, WidgetService.class);
// prints the correct appWidgetId
System.out.println(appWidgetId);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
remoteView.setOnClickPendingIntent(R.id.Button01, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, remoteView);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
The Service looks like this:
public int onStartCommand(Intent intent, int flags, int startId){
if (intent != null && intent.getExtras() != null) {
int widgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
// 3 is always printend
System.out.println(widgetId);
// More stuff here
}
return super.onStartCommand(intent, flags, startId);
}
So what am I doing wrong?