Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass a Bundle to startActivityForResult to achieve Scene Transitions

I am playing around with Lollipop sceneTransitionAnimations.

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

Then, when you call startActivity you have to pass a Bundle to that function that you obtain by calling ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle().

This works fine. However I need to start an activity using startActivityForResult. This function only takes an Intent and a requestCode, but no Bundle. Putting the bundle into the intent using putExtras did not work.

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

EDIT as I was asked for code:

I am inside a Fragment, I have a list of items. When an item is clicked I start another activity.

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

now here come the two distinctions. This one works:

getActivity().startActivity(intent, bundle);

The Fragment does not offer this function, so I have to use its parent activity's - hence the getActivity().

This one does not work:

intent.putExtras(bundle);
startActivity(intent);
like image 786
kunterbunt Avatar asked Jun 23 '15 00:06

kunterbunt


1 Answers

Thanks to Squonk I have come to realize that the method I am trying to use, startActivityForResult(Intent intent, int requestCode, Bundle options) actually exists.

I had done the mistake of trying to start that from a Fragment, where it is not implemented - same as startActivity(Intent intent, Bundle bundle) - so you need to call getActivity().startActivityForResult(Intent intent, int requestCode, Bundle options) .

like image 90
kunterbunt Avatar answered Oct 09 '22 05:10

kunterbunt