Can not get value from notification when user click on notification while app is closed

open specific activity on notification click android
open app in specific view when user taps on push notification with ios swift
how to handle notification when app in background in firebase android
open activity from notification android
android notification click open new activity
handle push notification when app is in background ios swift
how to handle notification when app in foreground in firebase android
firebase web push notification example

how can I pass data like order_id in intent when the application is killed or closed???

My application working properly when the application is in the foreground or background. I can get value from intent (order_id).

I'm also able to open a specific activity when the application is closed by using click_action.

I'm having a problem with when the application when it is closed. I can't get order_id from notification's intent when the application is closed.
private void sendNotification(String title, String messageBody, Intent intent) {

     Intent intent = new Intent(getApplicationContext(), 
     Bundle bundle = new Bundle();
     bundle.putString("id", "Android");
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 , intent,PendingIntent.FLAG_UPDATE_CURRENT);
    public void onNewIntent(Intent intent) 
         Bundle bundle = intent.getExtras();
         Log.e(TAG, "onNewIntent: " + bundle.getString("id"));




                <action android:name="com.vonpharmacy.ui.activities.MyOrderDetailActivity" />
                <category android:name="android.intent.category.DEFAULT" />


still, I'm getting null value, I want to get the id in so I can get the detail and show order information.

You need to get data message for that purpose. By default if you send notification message in FCM then if the app is in background then the notification is shown by FCM itself and receiver is not called.

For data message it is called every time, whether the app is in foreground or background.

Read more

Push Notifications when app is closed, getName()); // Start the service, keeping the device awake while it is launching. When the app is closed forcelly by the user : notifications don't arrive You must send push messages with data payload because of data payload battery Optimization >> find your app >> select >> if optimized click on don't optimize >> try� Scheduling when notifications should appear - Periodically show a notification (interval-based) - Schedule a notification to be shown daily at a specified time - Schedule a notification to be shown weekly on a specified day and time - Ability to handle when a user has tapped on a notification when the app is the foreground, background or terminated

If you send notification directly from fcm console ,you cant get value from notification when app is closed.You use server, which helps you to send notification.Define only data,You cant define notification inside payload. For example;

payload = {

priority: "high",
content_available: true,
   type: 'type',
   id: id,



Handling Notifications and Notification-Related Actions, If your app supports actionable notification types, you must handle the associated actions. Match the value in the actionIdentifier property of the response object to one of your If the user doesn't choose one of the app-defined actions, the method saves the Handle Notifications While Your App Runs in the Foreground. Windows 10 Notifications Does Nothing When I Click Whenever I get a notification message that asks me to click in order to take action, when I click, the notification goes away but nothing happens. Sometimes I get something like: "A new version of Java update is available.

I used the below way to firebase notifications. Especially when messages were sent from firebase console and my application was not able to call onMessageReceived method if the application was closed or in background.

The behavior of receiving the notifications is different (if the application is in the background or in foreground) Or say Closed or used by users.

The method below or service will only be called If the application is in the foreground, In other words, you can get the values from the intent.

public class PushNotificationMessagingService extends FirebaseMessagingService {

    public void onMessageReceived(final RemoteMessage message){

If your application is closed. In this case, your application will receive notifications and display them in the system tray. You have to click on the notification, you will receive the data in the onNewIntent method of your activity.

Receive messages in a JavaScript client, In order to receive the onMessage event, your app must define the Firebase messaging the user clicks on an app notification created by a service worker while the app is in the background trigger a display notification in the browser. If the link value points to a page that is already open in a browser tab, a click on the� a. From the Start Screen Launch the Windows 8 Mail App. b. While in the Windows 8 Mail App move the mouse in the bottom right hand corner to bring out the charms bar then click the settings button. c. Once in Settings, Click the Accounts button d. Once in the accounts choose the email account that you want to setup notifications for. e.

You can't receive any message onMessageReceived(final RemoteMessage message),if you directly send notification from firebase. You need to create a web service usinng php, java, python etc which hosted on any cluod or sharedhost . If you have not web service then you can use firebase cloud function or typescritp which is free to use.

Firebase notification has two type services one is notification and another is only data. if you directly send notification from firebase then only send notification to application .In these case app is running then not any issue but app in background can't handle manually. So notification handle on background and running mode if only send data.And only data can send possible by third party server.

Start an Activity from a Notification, Back up key-value pairs When you start an activity from a notification, you must preserve the user's Tapping Back should take the user back through the app's normal work flow So this activity does not need a back stack. Handling Notifications in Foreground. When the app is closed, your notifications are processed by the Google Service process, which take care of displaying your notifications as required, including the default click action (opening the app) and the notification icon.

try it;

$data = array((

    'data' => array("title" => $title, "text" => $notification, "customer_id" => $customer_id, "order_id" => $order_id, "type" => $type, "click_action" => "com.vonpharmacy.ui.activities.NotificationTestActivity"),//use this only

  //don't use this line//  'notification' => array("title" => $title, "text" => $notification, "customer_id" => $customer_id, "order_id" => $order_id, "type" => $type, "click_action" => "com.vonpharmacy.ui.activities.NotificationTestActivity")//don't use it, this is only for your knowledge .If use it get same problem before you got.


I hope this helps you.

Notifications Not Shown, Also check the network / WiFi you're connected as it may have closed your connection to Apple or 0 then no notification will show while the app is open. This is an activity that exists as a part of your app's normal UX flow. So when the user arrives in the activity from the notification, the new task should include a complete back stack, allowing them to press Back and navigate up the app hierarchy. Special activity The user only sees this activity if it's started from a notification.

onMessageRecieved not working when app is killed. � Issue #368 , It works perfect in foreground and in background and I can receive Extras in MainActivity. But when app is killed I receive notification and after click on it- Extras == null. How can I catch this extras when app is closed in other way?(( When a user kills an app it is an indication that the user does not want� It is not triggered for tile or toast push notifications. When receiving a raw, you can then execute code to locally send tile and toast notifications (in addition to updating your app's data so that the new data is already loaded when the user opens the app). You can learn about sending raw notifications here: Raw notification overview.

What are Push Notifications? A Complete Guide [Up-to-date], Web push notifications can be sent to users without the need to build an app as on your push notification marketing strategy – open-ended campaigns or closed campaigns. They no longer receive the remaining notifications in the series. Offer them value-based messaging to entice them into clicking and engaging� To get the message in the call back functions when you click on the notification you have to add an additional key and value into the push notification payload.

Push Notifications on the Open Web, The following code subscribes the user for push messaging: function subscribe() { // Disable the button so it can't be changed while // we process the permission� The app can receive notifications while running in foreground or background, but won't receive notifications when the app is killed. The same application is working fine on Nexus 5. Also I have another application which uses GCM implementation to receive notifications and it works fine on both devices even when the application is killed.

  • You get notification when app is close ?
  • yes, I can get a notification when the app is closed @Ali
  • Please check this answer ... It could be helpful
  • Can you share that php firebase payload message which you used.
  • $data = array( "title" => $title, "text" => $notification, "customer_id" => $customer_id, "order_id" => $order_id, "type" => $type, "click_action" => "com.vonpharmacy.ui.activities.NotificationTestActivity", );
  • no, I'm not having an issue with showing data in the notification tray. I can not get value from intent when the application is closed.
  • data message is a different kind of notification, you can set order_id with your notification, so you can pass it in intent, please read the link mentioned and read it carefully
  • @SavanPatel Yes. I understand. By default if it is a notification message then notification is shown by FCM itself, your code of showing notification is not working. It will always take you to the Splash screen of the app.
  • @ Rahul Gaur, You are right so how can I solve this.
  • @ Rahul Gaur I'm using click_action so it will open my order detail page directly from the notification.
  • Call the method "onNewIntent(getIntent());" from your onCreate method of activity
  • and let me know, if it's help