Pass a Bundle to startActivityForResult to achieve Scene Transitions

廉价感情. 提交于 2020-01-02 04:33:06

问题


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);

回答1:


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) .



来源:https://stackoverflow.com/questions/30991866/pass-a-bundle-to-startactivityforresult-to-achieve-scene-transitions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!