Reputation: 5091
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:
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??
Upvotes: 1
Views: 1223
Reputation: 11038
Can't you just call finish() right after your starActivity call? (you'd have to remove the SINGLE_TOP flag too -- or you'll run into the behaviour you mentioned when going from B -> B)
Upvotes: 1