I have an application with an AppWidget
. The AppWidget
has some buttons which when clicked must open an Activity
. The Activity
must change some object's values depending on the appWidgetId
of the AppWidget
that has started this Activity
. Here's a piece of code from the AppWidgetProvider
subclass:
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
for (int id : appWidgetIds) {
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget);
Intent localCodeIntent = new Intent(context,
CountrySelectorActivity.class);
localCodeIntent
.setAction(CurrencyRatesWidgetHelper.WIDGET_UPDATE_LOCAL_CURRENCY);
localCodeIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
PendingIntent localCodePI = PendingIntent.getActivity(context, 0,
localCodeIntent, 0);
views.setOnClickPendingIntent(R.id.local_iv, localCodePI);
The Activity
starts well, but when I'm trying to extract the appWidgetId
, I get the value of 1 everytime. Here's the Activity
's onCreate()
method code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
appWidgetId = intent
.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, 0);
action = intent.getAction();
I'm sure I'm making a mistake somewhere, but can't really figure it out. Thanks in advance.