1

I would like to know how applications such as WhatsApp is still able to navigate the user to right message screen even when WhatsApp is closed/terminated.

Does this imply that WhatsApp is not at all terminated but stays running in the background?

I need to implement the same feature in a react-native application. The push notification is working but when my app is terminated, it only opens the app to the main screen upon receipt of a push notification.

I would like to know:
1) If there exists a strategy to actually make it work similar to WhatsApp receiving pushnotifs even when it is terminated ?
2) Other technologies - e.g. OneSignal or Pusher - that offers this.

Please note that I am from an iOS background.

Thanks,
Avinash

Avinash Lingaloo
  • 181
  • 3
  • 16
  • 1
    You can use deep links. Refer here https://developer.android.com/training/app-links/deep-linking.html – Gautam Mar 16 '18 at 09:30
  • @Gautam Deeplinking (e.g. Branch.io or native) used to open app from a URL not from Notifcation. – Vishal Chhodwani Mar 16 '18 at 09:40
  • @VishalChhodwani you can pass a path or URL with the notification data and redirect user to the related page with that information. Common navigation libraries like react-navigation has this path feature built in already. [More info](https://reactnavigation.org/docs/deep-linking.html) – bennygenel Mar 16 '18 at 09:43
  • @VishalChhodwani you can use deep links from notification as well & its better to use the same if opening different activities, it keeps the code clean. While creating a pending intent, use setData over an intent and pass your URI, it will act as a deep link – Gautam Mar 16 '18 at 09:43
  • @bennygenel Not possible in Native Android, and Don't know about React Native(May be possible). For better hint I answered below, have a look. – Vishal Chhodwani Mar 16 '18 at 09:46
  • @VishalChhodwani question is seeking answers for react-native. that is why I tried to correct the information. – bennygenel Mar 16 '18 at 09:47
  • @bennygenel No problem, That's really a good job you are doing :) Thank you. – Vishal Chhodwani Mar 16 '18 at 09:49
  • I think on iOS this is not possible and a workaround like the one describe in this link should be implemented. Some inputs from the iOS community are the most welcomed. https://stackoverflow.com/questions/35058870/handling-push-notifications-when-app-is-terminated – Avinash Lingaloo Mar 16 '18 at 13:53
  • 1
    Possible duplicate of [How to navigate screen on notification open in React Native with One Signal?](https://stackoverflow.com/questions/46541163/how-to-navigate-screen-on-notification-open-in-react-native-with-one-signal) – bennygenel Mar 17 '18 at 06:53
  • @bennygenel thanks for pointing to the right direction. – Avinash Lingaloo Mar 17 '18 at 09:24

3 Answers3

0

No, it does not mean that app is running in background, if navigating to specific Activity from notification.

I am from Native Android platform, I can not give you exact code for react-native but can give you hint.

There is android component Named PendingIntent that is responsible to navigate from notification to specific Activity.

Native Android Code

Intent notificationIntent = new Intent(this, YourRedirectedActivity.class);

PendingIntent contentIntent = PendingIntent.getActivity(this, 100, notificationIntent, PendingIntent.FLAG_ONE_SHOT);

This code passed to the NotificationManager and display the notification.

So when user click on the notification it redirects to the above PendingIntent screen.

  1. Notification are working even app is terminated.
  2. Native Android(JAVA/Kotlin) offers this.

Hope it will move you the solution.

Vishal Chhodwani
  • 2,567
  • 5
  • 27
  • 40
0

In newest version of FCM it's automatically show notification when app in background. You can only got notify in Message Service Class of FCM when app is running.

When app in background, u can got notification data with bundle data in "the first running class", check intent then push to some other classes u want.

<intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
kemdo
  • 1,429
  • 3
  • 15
  • 29
0

I will using react-navigation deep linking feature with the Firebase FCM sending a deep-link (url ) which I will check and then navigate to.

Avinash Lingaloo
  • 181
  • 3
  • 16