`setEnterTransition` only works with` ActivityCompat.startActivity`

I want to add a transition transition to the next step.

So I did:

getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS); window.setEnterTransition(new Slide()); 

This does not work. After doing trial and error (since I had this transition working on other actions), I found out that it worked after the call

 ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, view, "some_name"); ActivityCompat.startActivity(activity, new Intent(TourAndLoginActivity.this, LoginActivity.class), activityOptionsCompat.toBundle()); 

But I do not have a common element (I added a view to check it). Cannot add 'null' as a generic element.

Is this really necessary for this? My workaround would be to add an invisible common element.

+5
source share
2 answers

taken from Android developer documentation:

Start an action using transitions. If you activate transitions and specify a transition to switch to activity, the transition is activated when another action is launched as follows:

 startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle()); 

If you set an input transition for the second action, the transition is also activated when the action begins. To disable transitions when starting another action, specify a pool of null options.

https://developer.android.com/training/material/animations.html

So, first enable the transitions, as you already do, as shown below:

 getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS); window.setEnterTransition(new Slide()); 

and then run the action as follows:

 startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle()); 
+6
source

You can add a transition during a call of this type

 Intent i = new Intent(context, SampleActivity.class); i.putExtra("data", data); startActivity(i); context.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); 
0
source

All Articles