The app has this flows:
1) Home -> Activity A -> Activity B -> Activity C -> Activity A -> Activity B -> Activity C -> etc.
2) Home -> Activity C -> Activity B -> Activity C -> Activity A -> Activity B -> Activity C -> etc.
3) Home -> Activity D -> Activity B -> Activity C -> Activity A -> Activity B -> Activity C -> etc.
Activity B has a button that must close all activities except Home and the first Activity. What is the best way to do it?
If I give same taskAffinity to A, B and C and use finishAffinity() then all activities will be closed.
Try this i.e, if you want to close all activities except MainActivity and open otherActivity from this.