I have a custom application that has multiple activities running in full screen (SplashActivity
, MainActivity
, InfoActivity
, and so on...). I'm currently working on notifications and i'm trying to have the following behavior: if the application is running and put to background and the user clicks the notification, the last activity that was running resumes. If the user is not running the application, then the SplashActivity
is launched. Is there a way to have this behavior? I'm using the following code
android.app.NotificationManager notificationManager = (android.app.NotificationManager) instance.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(instance, SplashActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(instance, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(instance);
builder.setSmallIcon(iconId);
builder.setContentTitle(title);
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
builder.setContentText(message);
builder.setContentIntent(contentIntent);
notificationManager.notify(0, builder.build());
If i set the activity to SplashActivity.class it will open that activity whether the application was running or not, so that would only be right if the application was not running.