0

There are 3 states that an app can be in : 1. Foreground. 2. Background(minimized) 3. Completely closed( removed from list of active applications)

This is the way I've done it : 1. Forground/Background -> onMessageReceived(RemoteMessage remoteMessage) is where I get all the messages which I further parse.

  1. Completely closed -> Intent processInputIntent = getIntent(); int id = processInputIntent.get("id"); // I fetch all the parameters this way. This method works if I don't do the following changes in the manifest.

The issue is my app is a complete webview and I need to save the state of the app and so I used android:alwaysRetainTaskState="true" android:launchMode="singleTask">

Is this the right way of handling things? Any help would be highly appreciated.

Roehit Kadam
  • 101
  • 1
  • 11

1 Answers1

1

So going by the comments. I deduce that the reason you are not getting intent data in activity after adding android:alwaysRetainTaskState="true" is because the task is being retained by the system and system is not creating a new task so now new Root Activity. But according to FCM Docs

When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default.

This includes messages that contain both notification and data payload (and all messages sent from the Notifications console). In these cases, the notification is delivered to the device's system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.

So, I think the solution to this issue is getting DATA PAYLOAD ONLY in onMessageReceived(). And Here is very important info regarding this method.

onMessageReceived() method will not be called if the app is in background or killed and if the message sent contains DATA and NOTIFICATION payload both.

When app is not running you will anyway receive notification. But if you want to intercept data via onMessageReceived() then you will have to create a custom app server which will send only DATA payload to fcm endpoint.

something like this:

 {
   "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
   "data" : {
     "Title" : "Title for Notification",
     "body" : "Notification body can go here",
     "Room" : "Something extra"
   },
 }

Let me know if it changes anything for you.

Nishant Dubey
  • 2,802
  • 1
  • 13
  • 18
  • Thanks for the analysis I have a better understanding of how "AlwaysRetaintask" is affecting my app. I'm okay with not intercepting the data in the onMessageReceived(). Right now since the onCreate() wasn't called because of the "AlwaysRetainTask" I tried a getIntent() in the onResume which is called and still the getIntent() doesn't receive anything. If I disable the "AlwaysRetainTask" the same works and I do get the information after a user clicks on the notification and the app is opened. – Roehit Kadam Sep 30 '16 at 21:06
  • The app isn't relaunching with **AlwaysRetainTask** that's why no intent in extras of **launcher Activity** *(where fcm sends data payload as intent)*. So I think solution really is to use onMessageReceived() or let system kill the task of your app – Nishant Dubey Sep 30 '16 at 21:11