Firstly, Stack structure can be examined. For the launch mode:singleTop
If an instance of the same activity is already on top of the task stack, then this instance will be reused to respond to the intent.
All activities are hold in the stack("first in last out") so if your current activity is at the top of stack and if you define it in the manifest.file as singleTop
android:name=".ActivityA"
android:launchMode="singleTop"
if you are in the ActivityA recreate the activity it will not enter onCreate will resume onNewIntent() and you can see by creating a notification
Not:İf you do not implement onNewIntent(Intent) you will not get new intent.
Intent activityMain = new Intent(ActivityA.this,
ActivityA.class);
activityMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(activityMain);
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
notify("onNewIntent");
}
private void notify(String methodName) {
String name = this.getClass().getName();
String[] strings = name.split("\\.");
Notification noti = new Notification.Builder(this)
.setContentTitle(methodName + "" + strings[strings.length - 1])
.setAutoCancel(true).setSmallIcon(R.drawable.ic_launcher)
.setContentText(name).build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify((int) System.currentTimeMillis(), noti);
}