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 get 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 displayed? How to solve this? Please help. Thanks.

+8
android android-intent notifications
source share
1 answer

You pass Intent.FLAG_ACTIVITY_NEW_TASK when a method call expects the 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); 
+13
source share

All Articles