Lollipop activity transitions: Back button vs. back from toolbar differences?
Asked Answered
S

1

5

I have an app where I'm doing activity transitions for a company directory. When a search result is selected, the animation of their photo to the detail screen works. And if I hit the back button, the reverse animation occurs. However, if I hit the back arrow from the Toolbar, the reverse animation never occurs.

The detail screen is a new DetailActivity with a single fragment in it called DetailFragment. I'm not doing anything special on "onBackPressed". Should I be?

Stanford answered 17/11, 2014 at 19:20 Comment(2)
Well the 'Up' button in the toolbar is a different operation from the back button so they aren't quite the same thing (Up recreates the next level up and doesn't resume a previous instance by default for example)Lalo
Good point. developer.android.com/design/patterns/navigation.html So I assume animations should never occur when using the "Up" command, correct?Stanford
M
15

If you want the return transition to play, you'll need to listen for the up-navigation button click and call finishAfterTransition() directly:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            finishAfterTransition();
            return true;
    }
    return super.onOptionsItemSelected(item);
}
Maice answered 17/11, 2014 at 21:54 Comment(2)
supportFinishAfterTransition();Grease
why does the parentActivity functionality in AndroidManifest actually open a new activity, instead of closing all activities between this and the parent activity?Edrick

© 2022 - 2024 — McMap. All rights reserved.