Just as the title says...
I'm using a transition between activities, and I'd like to have some kind of listener (or event) for both activities, for when the transition has finished and for just before it started.
Here's a sample code of creating the transition:
final Intent intent = new Intent(activity, TargetActivity.class);
if (initialQuery != null)
intent.putExtra(EXTRA_INITIAL_QUERY, initialQuery);
final String transitionName = activity.getString(R.string.transition_name);
ViewCompat.setTransitionName(viewToTransitionFromAndTo, transitionName);
final ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
viewToTransitionFromAndTo, transitionName);
ActivityCompat.startActivityForResult(activity, intent, requestCode, options.toBundle());
You can add a listener to any of the transitions that you use. For example:
getWindow().getSharedElementTransition().addListener(listener);
This will listen for when the transition itself starts and ends. However, it doesn't give you the whole activity transition information. For example, the calling activity doesn't know when the called activity has finished its transition.
Assuming the transition on top is not marked translucent, the underlying transition will be told to stop -- onStop()
-- when the top activity has become opaque. That doesn't mean the transition has finished, it just means that the fade in of the top activity has finished. I can't think of much that you'd want to do once the activity has stopped, though. This won't help when the activity is translucent, though.
So, no, if you want to have both activities know about the transition, you'll have to hack it in. The called activity always knows when the transition finishes (using the listener) on enter and the calling activity always knows on exit.
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