I can't get Bandle from Notification

 public class NotificationsService extends FirebaseMessagingService { Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Intent intent = new Intent(this, MainActivity.class); intent.putExtra("notification", notificationModel); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOPIntent.FLAG_ACTIVITY_CLEAR_TOP); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(map.get("alert")) .setContentText(map.get("alert")) .setSmallIcon(R.drawable.com_facebook_button_icon) .setAutoCancel(false) .setContentIntent(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)) .setSound(sound); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = notificationBuilder.build(); notification.flags = Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0,notification); } 

And the MainActivity to which we are moving on PendingIntent

  @Override protected void onResume() { super.onResume(); Intent intent = getIntent(); notificationModel = (NotificationModel) intent.getSerializableExtra("notification"); if (notificationModel != null){ App.showLog(notificationModel.toString()); } } 

And in notificationModel comes null

    1 answer 1

      intent.putExtra("notification", notificationModel); 

    What is a notificationModel? Isn't it exactly null here?

      intent.addCategory(Intent.CATEGORY_LAUNCHER); 

    What for?

      intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOPIntent.FLAG_ACTIVITY_CLEAR_TOP); 

    Choo ???

    • Not exactly null, the flags allow you to open the already created activity, and the categories (optional and possibly superfluous) in this case allow launching launch_activty - Heaven
    • 2
      In the already created activity, you need to catch onNewIntent - the new intent comes only there and is not automatically saved, but you can save from there by calling setIntent . - woesss
    • All right, it helped - Heaven
    • It is not the answer to the question. To leave your comments or ask the author to clarify, leave a comment to the appropriate post. - From the queue of checks - kizoso
    • @kizoso But it is an excellent kick, which helped find the answer to the question. - bukkojot