Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing extras from widget in PendingIntent to Activity

I can't find a way to pass extras from widget to Activity properly.

I wan't to open activity on button click with some extras passed.

    Intent intent = new Intent(context, CreateOperationsActivity.class);
    intent.putExtra("someKey", true);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, Constants.RequestCodes.CREATE_OPERATIONS, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    views.setOnClickPendingIntent(R.id.add_expense_button, pendingIntent);

Activity is opened, but there is no extra in the Intent.

The only way I was able to pass that extra was seting PendingIntent flag to PendingIntent.FLAG_ONE_SHOT but then widget button works only wonce, clicking it further takes no action.

How to do that so the extra is intercepted by Activity and the button works each time?

like image 678
Jacek Kwiecień Avatar asked Jan 31 '15 16:01

Jacek Kwiecień


1 Answers

You're probably missing setAction() for your Intent ;) See this one for a better explanation: https://stackoverflow.com/a/3128271/515423

like image 170
vizZ Avatar answered Nov 16 '22 17:11

vizZ