Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`setEnterTransition` only works with `ActivityCompat.startActivity`

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.

like image 251
Boy Avatar asked Jun 03 '16 07:06

Boy


1 Answers

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());
like image 131
Ankit Aggarwal Avatar answered Oct 19 '22 12:10

Ankit Aggarwal