0

I have an android app which uses FCM for push notifications. There is a backend that sends push notifications

Every time user makes an image upload , a push notification is sent to whoever is subscribed to the topic.

On click of the notification in the notification tray I'm redirected to the first page of the app.

How can I make the push notifications work like how Instagram does.

On receiving a notification and clicking on it , I want to move to that particular screen and see the image that got uploaded.

If the user is in the app while the notification arrives. How to refresh the activity to display the content. Do I have to make a backend request to show the new data or can I display content from the notification itself?

Is there any example I can look at.

Any help will be appreciated. Thank you.

A.S
  • 798
  • 1
  • 10
  • 32

1 Answers1

1

To start an activity that includes a back stack of activities, you need to create an instance of TaskStackBuilder and call addNextIntentWithParentStack(), passing it the Intent for the activity you want to start.

As long as you've defined the parent activity for each activity as described above, you can call getPendingIntent() to receive a PendingIntent that includes the entire back stack.

// Create an Intent for the activity you want to start
 Intent resultIntent = new Intent(this, ResultActivity.class);

// Create the TaskStackBuilder and add the intent, which inflates the back 
 stack

 TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
  stackBuilder.addNextIntentWithParentStack(resultIntent);

// Get the PendingIntent containing the entire back stack
  PendingIntent resultPendingIntent =
    stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
niya panchal
  • 91
  • 1
  • 8