In your case where you are not sure to which Activity to be open on Notification click . Then you should broadcast on Notification click .
Create a Broadcast Reaceiver.
class NotificationClickReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
// here you will get Intent
// Check which activity is currently open and pass the data to it
// For passing data you can use a Another BroadcastReceiver or
}
}
Entry in manifest
<receiver
android:name=".NotificationClickReceiver"
/>
Then use pendingIntent to getBroadcast on notification click
Intent intent = new Intent(this, NotificationClickReceiver.class);
intent.putExtra("key","val");
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 3, intent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable._logo)
.setContentText(notification)
.setContentTitle(title)
.setAutoCancel(true)
.setSound(defaultSoundUri);
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
Now you will get intent in onReceive of NotificationClickReceiver then you can figure out to which activity to pass it on.