I have a code in the service:

Intent intent = new Intent(this,ActivityFragments.class); intent.putExtra("ExamFragment","ExamFragment"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,0); mBuilder.setContentIntent(pendingIntent); mBuilder.setSmallIcon(R.drawable.icon); mBuilder.setContentTitle("Уведомление"); mBuilder.setContentText("Вам нужно срочно проверить результаты"); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(001, mBuilder.build()); 

This code triggers a notification. How do I do this: Write a key in PendingIntent and transfer its activity (when you click on the notification), and accordingly get it?

    1 answer 1

    You need to put the necessary data in the Intent , on the basis of which your PendingIntent is created. You need to put in the Bundle intent. There are two ways to do this:

    1. Create an object of type Bundle, fill it with data using methods of type Bundle#putString("key", "value") and assign it to the intent using the method Intent#putExtras(Bundle b)
    2. Put the info into the existing Instance Bundle using the Intent#putExtra("key", value) where value is a primitive or an object that implements Parcelable or Serializable interfaces

    Then, after clicking on the notification, in your case the actiti starts and its Activity#onNewIntent(Intent intent) method is called where the Activity#onNewIntent(Intent intent) created and filled by you comes, from which you can get the data you have written