本文介绍了共享元素转换中的IllegalArgumentException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已实施的活动到活动共享元素过渡。它工作正常,但在运行> = LOLLIPOP的极少数设备上收到崩溃信息。

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

报告:

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

尝试过此操作:

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

两个代码都发生崩溃:

startActivity(intent, options.toBundle());

有没有遇到过?有任何提示吗?

Ever faced ? Any hints ?

推荐答案

似乎您正在使用 Window.FEATURE_CONTENT_TRANSITIONS 。但是,相反,您应该使用 Window.FEATURE_ACTIVITY_TRANSITIONS

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

在您的 styles-v21中.xml ,添加:

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

从文档中:

TransitionManager 是使用 setTran设置的sitionManager(TransitionManager)。如果未设置,则将使用默认的TransitionManager。

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

请参见以获取更多信息。

See this post for more info.

这篇关于共享元素转换中的IllegalArgumentException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 08:02