Pass the package to startActivityForResult to achieve hopping transitions

I play with Lollipop sceneTransitionAnimations.

To make it work, you need to implement getWindow().setExitTransition()+ getWindow().setReenterTransition()in the calling activity onCreate, and getWindow().setEnterTransition()+ getWindow().setReenterTransition()in the called activity onCreate.

Then, when you call startActivity, you must pass Bundlethis function, which you get by calling ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle().

It works great. However, I need to get started with startActivityForResult. This function accepts only Intenta requestCode, but not Bundle. Attaching a beam to an intent using putExtrasdid not work.

How do I make these nice Lollipop transitions work when I want to use startActivityForResult?

EDIT because I was asked to enter the code:

I am inside a fragment, I have a list of items. When an item is clicked, I trigger another action.

Intent intent = new Intent(context, otherActivity.class);
Bunde bundle = null; 
if (android.os.Build.VERSION.SDK_INT >= 21)
    bundle = ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle();

now two differences come. It works:

getActivity().startActivity(intent, bundle);

A fragment does not offer this feature, so I need to use its parent activity - hence getActivity().

This work is not :

intent.putExtras(bundle);
startActivity(intent);
+4
source share
1 answer

Thanks to Squonk, I realized that the method I'm trying to use startActivityForResult(Intent intent, int requestCode, Bundle options)does exist.

I made a mistake trying to start this from a fragment where it is not implemented - just like startActivity(Intent intent, Bundle bundle)- so you need to call getActivity().startActivityForResult(Intent intent, int requestCode, Bundle options).

+8
source

All Articles