Intent from notification does not have extras

后端 未结 6 674
野性不改
野性不改 2020-12-07 22:38

This seem to be a common problem and I went through all the related questions I could find already: Activity isn't picking up new intent, Why extra data (integer) is not

6条回答
  •  渐次进展
    2020-12-07 22:46

    1. If not needed then avoid setting your activity in manifest as a single task. omit this line or change it to singleTop if you can:

        android:launchMode="singleTask”
      
    2. If you must have a single task then in pending intent set flags to : Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK And PendingIntent.FLAG_CANCEL_CURRENT.

      resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |Intent.FLAG_ACTIVITY_CLEAR_TASK);
      pIntent = PendingIntent.getActivity(context, 0, resultIntent,    PendingIntent.FLAG_CANCEL_CURRENT );
      
    3. If you have a single task - Reset your extras in your activity inside onNewIntent() by setIntent(intent);

      protected void onNewIntent(Intent intent) {
             setIntent(intent);
             ... 
       }
      

提交回复
热议问题