I want to add an enter transition to the next activity.
So I did:
getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
window.setEnterTransition(new Slide());
This doesn't seem to work. After doing some trial and error (as I had this transition working on other activities) I found out that it did work after calling
ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, view, "some_name");
ActivityCompat.startActivity(activity, new Intent(TourAndLoginActivity.this, LoginActivity.class), activityOptionsCompat.toBundle());
But I have no shared element (I added a view just to test it). It is not possible to add 'null' as shared element.
Is it really mandatory to do it this way? My workaround would be to add an invisible shared element.
taken from android developers documentation:
Start an activity using transitions If you enable transitions and set an exit transition for an activity, the transition is activated when you launch another activity as follows:
startActivity(intent,
ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
If you have set an enter transition for the second activity, the transition is also activated when the activity starts. To disable transitions when you start another activity, provide a null options bundle.
https://developer.android.com/training/material/animations.html
So first enable the transitions as you are already doing like the following:
getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
window.setEnterTransition(new Slide());
and then start activity as follows:
startActivity(intent,
ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With