title: How to get title and message of notification and display on textview in new activity
body: <p>I am new to Android. I have tried all the possible ways from Stack Overflow links and other websites but not able to do it.</p>
  
  <p>I am able to generate notification from Cloud Messaging Firebase. But now I want to take title and message of notification and display on My Cart Activity in textview or listview. I have tried static, intent and interface methods. But I am not able to achieve it.</p>
  
  <p>This is for a final year project demo. Below is my code</p>
  
  <p>MyFirebaseInstanceIDService class    </p>
  
  <pre><code>public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
  
  private static final String TAG = "MyFirebaseIIDService";
  
  @Override
  public void onTokenRefresh() {
      String refreshedToken = FirebaseInstanceId.getInstance().getToken();
      Log.d(TAG, "Refreshed token: " + refreshedToken);
      storeToken(refreshedToken);
  }
  
  private void storeToken(String token) {
      //saving the token on shared preferences
      SharedPrefManager.getInstance(getApplicationContext()).saveDeviceToken(token);
  }
  }
  </code></pre>
  
  <p>MyFirebaseMessagingService class</p>
  
  <pre><code>public class MyFirebaseMessagingService extends FirebaseMessagingService {
  
  private static final String TAG = "MyFirebaseMsgService";
  
  @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
      if (remoteMessage.getData().size() &gt; 0) {
          Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());
          try {
              JSONObject json = new JSONObject(remoteMessage.getData().toString());
              sendPushNotification(json);
          } catch (Exception e) {
              Log.e(TAG, "Exception: " + e.getMessage());
          }
      }
  }
  
  //this method will display the notification
  //We are passing the JSONObject that is received from
  //firebase cloud messaging
  private void sendPushNotification(JSONObject json) {
      //optionally we can display the json into log
      Log.e(TAG, "Notification JSON " + json.toString());
      try {
          //getting the json data
          JSONObject data = json.getJSONObject("data");
  
          //parsing json data
          String title = data.getString("title");
          String message = data.getString("message");
          String imageUrl = data.getString("image");
  
          //creating MyNotificationManager object
          MyNotificationManager mNotificationManager = new MyNotificationManager(getApplicationContext());
  
          //creating an intent for the notification
          Intent intent = new Intent(getApplicationContext(), MainActivity.class);
  
          //if there is no image
          if(imageUrl.equals("null")){
              //displaying small notification
              mNotificationManager.showSmallNotification(title, message, intent);
          }else{
              //if there is an image
              //displaying a big notification
              mNotificationManager.showBigNotification(title, message, imageUrl, intent);
          }
      } catch (JSONException e) {
          Log.e(TAG, "Json Exception: " + e.getMessage());
      } catch (Exception e) {
          Log.e(TAG, "Exception: " + e.getMessage());
      }
  }
  
  }
  </code></pre>
  
  <p>MyNotificationManager class below</p>
  
  <pre><code>public class MyNotificationManager {
  
  public static final int ID_BIG_NOTIFICATION = 234;
  public static final int ID_SMALL_NOTIFICATION = 235;
  
  private Context mCtx;
  
  public MyNotificationManager(Context mCtx) {
      this.mCtx = mCtx;
  }
  
  //the method will show a big notification with an image
  //parameters are title for message title, message for message text, url of the big image and an intent that will open
  //when you will tap on the notification
  public void showBigNotification(String title, String message, String url, Intent intent) {
      PendingIntent resultPendingIntent =
              PendingIntent.getActivity(
                      mCtx,
                      ID_BIG_NOTIFICATION,
                      intent,
                      PendingIntent.FLAG_UPDATE_CURRENT
              );
  
      NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
      bigPictureStyle.setBigContentTitle(title);
      bigPictureStyle.setSummaryText(Html.fromHtml(message).toString());
      bigPictureStyle.bigPicture(getBitmapFromURL(url));
      NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mCtx);
      Notification notification;
      notification = mBuilder.setSmallIcon(R.mipmap.ic_launcher).setTicker(title).setWhen(0)
              .setAutoCancel(true)
              .setContentIntent(resultPendingIntent)
              .setContentTitle(title)
              .setStyle(bigPictureStyle)
              .setSmallIcon(R.mipmap.ic_launcher)
              .setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_launcher))
              .setContentText(message)
              .build();
  
      notification.flags |= Notification.FLAG_AUTO_CANCEL;
  
      NotificationManager notificationManager = (NotificationManager) mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
      notificationManager.notify(ID_BIG_NOTIFICATION, notification);
  }
  
  //the method wi
  //
  //
  // +-ll show a small notification
  //parameters are title for message title, message for message text and an intent that will open
  //when you will tap on the notification
  public void showSmallNotification(String title, String message, Intent intent) {
      PendingIntent resultPendingIntent =
              PendingIntent.getActivity(
                      mCtx,
                      ID_SMALL_NOTIFICATION,
                      intent,
                      PendingIntent.FLAG_UPDATE_CURRENT
              );
  
  
      NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mCtx);
      Notification notification;
      notification = mBuilder.setSmallIcon(R.mipmap.ic_launcher).setTicker(title).setWhen(0)
              .setAutoCancel(true)
              .setContentIntent(resultPendingIntent)
              .setContentTitle(title)
              .setSmallIcon(R.mipmap.ic_launcher)
              .setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_launcher))
              .setContentText(message)
              .build();
  
      notification.flags |= Notification.FLAG_AUTO_CANCEL;
  
      NotificationManager notificationManager = (NotificationManager) mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
      notificationManager.notify(ID_SMALL_NOTIFICATION, notification);
  }
  
  //The method will return Bitmap from an image URL
  private Bitmap getBitmapFromURL(String strURL) {
      try {
          URL url = new URL(strURL);
          HttpURLConnection connection = (HttpURLConnection) url.openConnection();
          connection.setDoInput(true);
          connection.connect();
          InputStream input = connection.getInputStream();
          Bitmap myBitmap = BitmapFactory.decodeStream(input);
          return myBitmap;
      } catch (IOException e) {
          e.printStackTrace();
          return null;
      }
  }
  }
  </code></pre>