Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 515
bryan Avatar asked Nov 17 '14 19:11

bryan


1 Answers

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);
}
like image 97
Alex Lockwood Avatar answered Nov 02 '22 11:11

Alex Lockwood