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

2.3k views Asked by At

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?

1

There are 1 answers

2
Alex Lockwood On BEST ANSWER

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);
}