Navigate To Different Activities On Notification Click
I have this scenario when user clicks the notification then, if the app is opened/foreground I want to redirect the user to HomeActivity else redirect the user to SplashActivity as
Solution 1:
To redirect the user to a specific Activity based on your logic you can use PendingIntent.
To check a working example click here.
OR
try below code on button click.
NotificationCompat.Builderbuilder=newNotificationCompat.Builder(this);
builder.setSmallIcon(android.R.drawable.ic_dialog_alert);
Intentintent=newIntent(Intent.ACTION_VIEW, Uri.parse("https://www.stackoverflow.com/"));
PendingIntentpendingIntent= PendingIntent.getActivity(this, 0, intent, 0);
builder.setContentIntent(pendingIntent);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
builder.setContentTitle("Notifications Title");
builder.setContentText("Your notification content here.");
builder.setSubText("Tap to view the website.");
NotificationManagernotificationManager= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Will display the notification in the notification bar
notificationManager.notify(1, builder.build());
To check if your app is in the foreground or not Check out this post.
Solution 2:
After some searching in this forum I got this post , taking some guidance from that I figured out a solution, on notification click I am redirecting every intent to HomeActivity and in onCreate() put my code to check if authentication is done or not(before setContentView()). If the authentication is not done redirect to SplashActivity and finish the current activity, otherwise continue.
Post a Comment for "Navigate To Different Activities On Notification Click"