Search code examples
androidandroid-transitionsshared-element-transition

Android L transition and home up button


I am using the new Android L transition, in particular shared element transitions along with a Slide(). When I press the back button the transitions work perfectly, it slides and transitions the shared ImageView to the correct spot but when I press the home-up button in the ActionBar it ignores the new transitions.

I set this block of code in the receiving activity:

    getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    getWindow().setExitTransition(new Slide());
    getWindow().setEnterTransition(new Slide());

And this block of code in my 'Main' Activity:

    getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    Transition transition = new Slide();
    getWindow().setSharedElementEnterTransition(transition);
    getWindow().setSharedElementExitTransition(transition);

Solution

  • Make sure you call finishAfterTransition() when the action bar's up button is clicked:

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finishAfterTransition();             
                return true;
        }
        return super.onOptionsItemSelected(item);
    }