Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PendingIntent error ( Must be one or more of: PendingIntent.FLAG_ONE_SHOT …..)

I am trying to create a PendingIntent in Android. Here is the code

mNotificationIntent = new Intent(getApplicationContent(), MyAlarm.class);
mContentIntent = PendingIntent.getActivity(getApplicationContext(),
                   0, mNotificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);

and I am getting the following error:

  Must be one or more of: PendingIntent.FLAG_ONE_shot,PendingIntent.FLAG_NO_CREATE, 
         PendingIntent.FLAG_UPDATE_CURRENT, 
         Intent.FILL_IN_ACTION, Intent.FILL_IN_DATA, Intent.FILL_IN_CATEGORIES…..)

Why is this error showing ? How to resolve this? Please help. Thank you.

like image 581
Boomerang Avatar asked Aug 31 '15 05:08

Boomerang


1 Answers

You are passing Intent.FLAG_ACTIVITY_NEW_TASK when the method call expects a PendingIntent flag. If you want to add Intent.FLAG_ACTIVITY_NEW_TASK to your Intent, you need to do it like this:

mNotificationIntent = new Intent(getApplicationContent(), MyAlarm.class);
mNotificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContentIntent = PendingIntent.getActivity(getApplicationContext(),
               0, mNotificationIntent, 0);
like image 155
David Wasser Avatar answered Sep 21 '22 11:09

David Wasser