I'm trying to create a basic app using the AppCompat Drawer, and multiple top-level activities (Not fragments) - I can't quite work out how to manage the backstack - I've tried about a hundred different approaches - but they all require some sort of weird hack to either clear the backstack - or finish the existing activity.
I have 3 activities - A, B & C. A & B are top-level, C is a child of B
I want:
- To start Activity A when the app starts
- To exit the app when I press the back button from A
- To start Activity B from the drawer
- To exit the app when I press the back button from B
- To start Activity C from Activity B
- To go back to Activity B when I press the back button from C
- When I start B from B or A from A or B from C by selecting drawer buttons - I should get the top-level Activity back in it's vanilla state.
I have:
protected void startActivity(Class activity) {
final Intent intent = new Intent(this, activity);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
overridePendingTransition(0, 0);
}
Basically I pass in either ActivityA.class or ActivityB.class - with this approach - pressing back from B takes me to A
Using HO_HISTORY, looks ok - but pressing back from C exits the app
Using REORDER_TO_FRONT doesn't seem to do anything??
Using finish() after startActivity works perfectly - unless you choose A or B twice (in which case you exit the app)
Using FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK works perfectly in every manner - except for the super nasty screen flashing as tasks are re-created. And the performance hit...
Help??