IllegalArgumentException in Shared Element Transition

不打扰是莪最后的温柔 提交于 2019-12-10 14:57:05

问题


Implemented activity to activity shared element transition. It works fine but receiving crashes on very few devices that are running >=LOLLIPOP.

Report:

Fatal Exception: java.lang.IllegalArgumentException
       at android.os.Parcel.readException(Parcel.java:1550)
       at android.os.Parcel.readException(Parcel.java:1499)
       at android.app.ActivityManagerProxy.isTopOfTask(ActivityManagerNative.java:4654)
       at android.app.Activity.isTopOfTask(Activity.java:5557)
       at android.app.Activity.startActivityForResult(Activity.java:3903)
       at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
       at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:65)
       at android.app.Activity.startActivity(Activity.java:4146)
       at com.mypackage.Activity1.method1(Activity1.java:414). 

tried this:

Intent intent = new Intent(Activity1.this, Activity2.class);
     ActivityOptionsCompat options = ActivityOptionsCompat.
                    makeSceneTransitionAnimation(Activity1.this,
                            logoImageView,
                            ViewCompat.getTransitionName(logoImageView));
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                startActivity(intent, options.toBundle());
            } else {
                startActivity(intent);
            }
            overridePendingTransition(R.anim.stay, R.anim.stay); 

then this from this sof IllegalArgumentException in ActivityManagerProxy:

Intent intent = new Intent(Activity1.this, Activity2.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    ActivityOptions options = ActivityOptions
            .makeSceneTransitionAnimation(Activity1.this,
                    logoImageView,
                    getString(R.string.splashLogoSharedTransition));
    startActivity(intent, options.toBundle());
} else {
    ActivityOptionsCompat options = ActivityOptionsCompat.
            makeSceneTransitionAnimation(SplashActivity.this,
                    logoImageView,
                    getString(R.string.splashLogoSharedTransition));
    ActivityCompat.startActivity(SplashActivity.this, intent, options.toBundle());
}
overridePendingTransition(R.anim.stay, R.anim.stay);  

Crash happens with the both the codes at:

startActivity(intent, options.toBundle());  

Ever faced ? Any hints ?


回答1:


It seems like you are using Window.FEATURE_CONTENT_TRANSITIONS. But Instead, you should be using Window.FEATURE_ACTIVITY_TRANSITIONS.

In your styles-v21.xml, add:

<item name="android:windowActivityTransitions">true</item>
<!-- optional -->
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item> 

From the Docs :

Window.FEATURE_CONTENT_TRANSITIONS:

Enables Activities to run Activity Transitions either through sending or receiving ActivityOptions bundle created with makeSceneTransitionAnimation(Activity, Pair[]) or makeSceneTransitionAnimation(Activity, View, String).

Window.FEATURE_ACTIVITY_TRANSITIONS:

Flag for requesting that window content changes should be animated using a TransitionManager.

The TransitionManager is set using setTransitionManager(TransitionManager). If none is set, a default TransitionManager will be used.

See this post for more info.




回答2:


According to this post you shouldn't use ActivityOptionsCompat above API 21: https://stackoverflow.com/a/42455484/1067763

I don't use it, but I still have this crash:

Crashes after startActivityForResult in API 27

I think it's still using the wrong version somehow.

Still, knowing this you might be able to solve your issue.



来源:https://stackoverflow.com/questions/47074027/illegalargumentexception-in-shared-element-transition

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