-4

I am having notification as follows. Notification 1 Notification 2 Notification 3 Notification 1 Notification 2

When user pressed, "Notification 1". "Notification 1" has to be sent to another activity.

When user pressed, "Notification 2". "Notification 2" has to be sent to another activity.

Any help

4 Answers4

0

Save your notification data in a string and pass it using intent in next activity on your click event.

See ref. : pass data between activities in android

Community
  • 1
  • 1
0

You have to use PendingIntent for opening an Activity on click of Notification.

first create a common Activity that should be used in PendingIntent.

And set some identical String on that PendingIntent by intent.putString("key", "notification1") or intent.putString("key", "notification2").

and on that Common Activity get that String you passed. No from that Common Activity according to your identical data start your Activity.

thats it.

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

An action takes users directly from the notification to an Activity in your application, where they can look at the event that caused the notification or do further work. Inside a notification, the action itself is defined by a PendingIntent containing an Intent that starts an Activity in your application.

How you construct the PendingIntent depends on what type of Activity you're starting. When you start an Activity from a notification, you must preserve the user's expected navigation experience.Part of designing a notification is preserving the user's expected navigation experience.There are two general situations:

  1. Regular - You're starting an Activity that's part of the application's normal workflow
  2. Special - The user only sees this Activity if it's started from a notification. In a sense, the Activity extends the notification by providing information that would be hard to display in the notification itself.

That is your answer, you can use share preference as a middle man to store small information linking your activation's to each activity.

Remario
  • 3,813
  • 2
  • 18
  • 25
0

Attaching snippet with comments -

NotificationManager mNotificationManager = (NotificationManager)
                this.getSystemService(Context.NOTIFICATION_SERVICE);

        Intent intent = new Intent(this, HomeActivity.class); // Redirected to HomeActivity
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        int _notificationId = (int) System.currentTimeMillis();
        String _message = remoteMessage.get("text");

        intent.putExtra(KEY_NOTIF_ID, _notificationId);

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                intent, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder mBuilder =
                (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.ic_notification_small) // Providing and icon
                        .setAutoCancel(true) // AutoCancelable
                        .setContentTitle(getResources().getString(R.string.app_name)) // Title
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText(_message))
                        .setContentText(_message) // Message
                        .setContentIntent(contentIntent); // This will the intent to start an activity once Notification is clicked
        mNotificationManager.notify(_notificationId /* ID of notification */, mBuilder.build());
Paresh P.
  • 6,677
  • 1
  • 14
  • 26