Why the PendingIntent doesn't send back my custom Extras setup for the Intent?

后端 未结 5 745
甜味超标
甜味超标 2020-12-01 13:51

This questions somehow relates to the question when I was looking to get the extras back in startActivityForResult but now I face another challenge.

I have subscribe

5条回答
  •  感动是毒
    2020-12-01 14:37

    I had this problem and the solution I found was quite simple, though I can't explain why it worked.

    Initially my pending intent looked like this:

         notificationIntent = new Intent(ctx, FragmentTabsPager.class);
         notificationIntent.setData(Uri.parse("content://com.sbs.mobile.workorder.WorkOrder/notes/"));
         notificationIntent.putExtra("NOTIFICATION", true);   
         notificationIntent.putExtra(WorkOrder.WorkOrderColumns.WORKORDERID, submessage);
    

    When creating the intent like this, no extras would be passed when the notification was clicked, the extras map would be empty in the receiving activity. I made the following change to the line initializing the notificationIntent:

         notificationIntent = new Intent().setClass(ctx, FragmentTabsPager.class);
    

    Now the extras are populated in the receiving activity. Again, I can't explain why this works but it fixed my problem.

提交回复
热议问题