In Android I have some activities, let\'s say A, B, C.
In A, I use this code to open B:
Intent intent = new Intent(this, B.class);
startActivity(inte
You can use this example to call your Activity A from Activity C
Intent loout = new Intent(context, LoginActivity.class);
loout.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(loout);
Starting in API 16 (Jelly Bean), you can just call finishAffinity().
Now you can also call ActivityCompat.finishAffinity(Activity activity) with the compatibility library.
Be sure to set taskAffinity in the manifest to a package name unique to that group of activities.
See for more info:
http://developer.android.com/reference/android/support/v4/app/ActivityCompat.html#finishAffinity%28android.app.Activity%29
In kotlin it is almost same like java. Only | symbol is replaced by or text. So, it is written like-
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
Use finishAffinity(); in task C when starting task A to clear backstack activities.
android:launchMode="singleTop" to the activity element in your manifest for Activity Aintent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) and
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) when starting Activity AThis means that when Activity A is launched, all tasks on top of it are cleared so that A is top. A new back stack is created with A at the root, and using singleTop ensures you only ever launch A once (since A is now on top due to ..._CLEAR_TOP).
Intent.FLAG_ACTIVITY_CLEAR_TOP will not work in this case. Please use (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
For more detail please check out this documentation.