Reputation: 56199
How to pass parameter to activity from widget from screen ? I have widget on screen and code like this
Intent defineIntent2 = new Intent(context, LOG.class);
defineIntent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
defineIntent2.putExtra("id", id);
PendingIntent pendingIntent2 = PendingIntent
.getActivity(context, 0 /* no requestCode */,
defineIntent2, 0 /* no flags */);
remoteViews
.setOnClickPendingIntent(R.id.widget, pendingIntent2);
but when I click on widget and enter at LOG activity and try to read that parameter I have passed ( id)
int id = getIntent().getIntExtra("id",
-1);
I always get -1. How to pass parameter from widget to activity ?
Upvotes: 0
Views: 1306
Reputation: 1346
Intents are reused in Android. If you want the changes you make deliver correctly, you can use FLAG_CANCEL_CURRENT FLAG:
PendingIntent pendingIntent2 = PendingIntent
.getActivity(context, ,
defineIntent2, PendingIntent.FLAG_CANCEL_CURRENT);
Upvotes: 3