0

I am having a notification screen .When notification receives and i tap on notification it will navigate to particular screen.The issue is when i am in the notification screen and i am getting a new notification the on new intent is returning old data.I am calling webservice from the number getting from notication .Because of this i am stuck .Could any one help me.below is the code

 notificationIntent.putExtra("from","notification");
    notificationIntent.putExtra(Constants.NUMBER,task);
    notificationIntent.setAction(Long.toString(uniqueInt));
    notificationIntent.addCategory(taskNumber);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, new Random().nextInt(), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

and in onNewIntent

  if(null != getIntent() && getIntent().getExtras() != null){
        if(getIntent().getExtras().containsKey(Constants.NUMBER))
        {
            String taskNumber = getIntent().getExtras().getString(Constants.NUMBER);

            if(null != taskNumber)
            {
                taskNumber = getIntent().getExtras().getString(Constants.NUMBER);
                loadTasks(taskNumber);
            }
Sujiz
  • 1,720
  • 1
  • 20
  • 30
  • 1
    When you call `getIntent()` it returns the original `Intent` that the `Activity` was started with. In `onNewIntent()` you need to use the `Intent` that is passed in the call to `onNewIntent()`. – David Wasser Aug 05 '19 at 15:26

1 Answers1

1

onNewIntent has new intent as argument. So you can use it directly or you can set it as starter Intent .

 @Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent); // Optional if you want set it as starter intent
    // Do your stuff with `getIntent()` OR intent

}
ADM
  • 20,406
  • 11
  • 52
  • 83