In Android N
while using split screen I want to launch activity
in current active window when user clicks on notification, but Android N always launches activity
in second window if launch by clicking on notification.
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification)
.setAutoCancel(false)
.setContentTitle("Demo Title")
.setContentText("Demo");
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("myIntent", "test");
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(pendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = mBuilder.build();
notification.flags = Notification.FLAG_NO_CLEAR;
mNotificationManager.notify(156, notification);
When get intent
than launch activity
.
Intent in = new Intent(MainActivity.this, SecondActivity.class);
startActivity(in);
ex - I have two apps in foreground like Chrome browser in first window & Facebook in second window now I am searching something in Chrome browser, at this moment I receive notification of Gmail
. Now when I click on Gmail notification than Gmail app open in second window by replacing Facebook but I want that my app notification replace Chrome(whom with user interact) in first window.