Are Activity/Fragment Transitions compatible with pre-Lollipop devices?

Cheborra picture Cheborra · Oct 25, 2014 · Viewed 18.2k times · Source

I'm trying to make an Activity Transition using Shared Elements on a pre-Lollipop device (4.x). Is it possible? So far, I'm trying this:

public class RewardDetail extends ActionBarActivity {
    @Override
    public void onCreate(final Bundle savedInstanceState) {
        ...

        ViewCompat.setTransitionName(imageView, TRANSITION_NAME);
    }

    ...

    public static void launch(ActionBarActivity activity, View transitionView, WelcomeReward detailData) {
        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, transitionView, TRANSITION_NAME);
        Intent intent = new Intent(activity, RewardDetail.class);
        intent.putExtra(PARAM_DATA, detailData);
        ActivityCompat.startActivity(activity, intent, options.toBundle());
    }
}

called by:

@Override
public void onClick(final View v) {
    int position = recyclerView.getChildPosition(v);
    WelcomeReward welcomeReward = data.get(position);
    RewardDetail.launch(WelcomeRewardActivity.this, v.findViewById(R.id.reward_view), welcomeReward);
}

But it results in a "regular" transition (no shared element). Any ideas?

EDIT

According to this video, it could be done:

https://www.youtube.com/watch?v=RhiPJByIMrM&index=8&list=WL

Is there a library already implementing this for pre Lollipop ?

Answer

Alex Lockwood picture Alex Lockwood · Oct 26, 2014

No, Activity/Fragment Transitions are not possible on pre-Lollipop devices. According to the documentation:

Start an activity with additional launch information, if able.

In Android 4.1+ additional options were introduced to allow for more control on activity launch animations. Applications can use this method along with ActivityOptionsCompat to use these animations when available. When run on versions of the platform where this feature does not exist the activity will be launched normally.

See also George Mount's answer to this StackOverflow question.