I have a use case where I mostly start an activity with a transition, but that's not the case when opening it from the navigation drawer.
To keep the transition smooth I have a Transition.TransitionListener
in which I trigger some UI updating when the transition is done.
So I have something like this:
public class SomeActivity extends Activity {
public void onCreate(Bundle savedInstanceState){
// ...
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
Transition sharedElementEnterTransition = getWindow().getSharedElementEnterTransition();
sharedElementEnterTransition.addListener(new Transition.TransitionListener() {
// ...
@Override
public void onTransitionEnd(Transition transition) {
doSomeUiUpdating();
}
});
} else { // Pre-Lollipop
doSomeUiUpdating();
}
}
}
This works well when starting the Activity with the animation, but how can I know if the Activity was started without a transition so that I can call doSomeUiUpdating()
?
I'm sure there must be a simple method in Activity
, Window
, Transition
or somewhere that I have overlooked. I don't want to relay on the calling Activity to set some bundle that telling if the animation is showing or not.
getTargets()
method ofTransition
(sharedElementEnterTransition.getTargets().isEmpty()
) if it is empty or not? It's not null anyway and numbers of TargetViews maybe the solution here.. – AmmunitiononTransitionStart
ofTransitionListener
to set some booleanisAnimationStarted
. – Vichy