问题:ActivityA启动ActivityB,共享元素转换间歇性崩溃 不一致可重复 Api水平:23,24和25
启动活动的代码:
Intent intent = new Intent(this, ActivityB.class);
Pair<View, String> logoTransition = Pair.create(logo, getString(R.string.transition_logo));
Pair<View, String> logoTextTransition = Pair.create(logoText, getString(R.string.transition_logo_text));
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, logoTransition, logoTextTransition);
ActivityCompat.startActivity(this, intent, options.toBundle());
Stacktrace(API 23):
Exception java.lang.IllegalArgumentException:
android.os.Parcel.readException (Parcel.java:1606)
android.os.Parcel.readException (Parcel.java:1555)
android.app.ActivityManagerProxy.isTopOfTask (ActivityManagerProxy.java:4787)
android.app.Activity.isTopOfTask (Activity.java:5753)
android.app.Activity.cancelInputsAndStartExitTransition (Activity.java:4075)
android.app.Activity.startActivityForResult (Activity.java:4052)
android.app.Activity.startActivity (Activity.java:4312)
android.support.v4.content.ContextCompat.startActivity (ContextCompat.java)
__null__.getDrawable (ContextCompat.java)
__null__.isDeviceProtectedStorage (ContextCompat.java)
com.my.app.activity.ActivityA.startMainActivity (ActivityA.java)
有谁知道导致这种行为的原因是什么? 对此有任何建议的解决方案吗?
答案 0 :(得分:3)
我想,您不应该使用支持库中的方法来获得该版本。当然,由于随机堆栈跟踪,我无法从您现有的问题中找出答案。
自Tranlsation场景引入4.4。您可以包含api弃用。此外,它建议,否则,为什么我们需要这两种类型?
if (Build.VERSION.SDK_INT >= 21) {
ActivityOptions options = ActivityOptions
.makeSceneTransitionAnimation(this, logoTransition, logoTextTransition);
startActivity(this, intent, options.toBundle());
}
else {
ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation(this, logoTransition, logoTextTransition);
ActivityCompat.startActivity(this, intent, options.toBundle());
}
答案 1 :(得分:2)
在我的情况下发生这种情况是因为我订阅了两次点击操作,因此连续两次调用startActivity。
希望这对某些人有用:)
答案 2 :(得分:0)
尝试在相关活动的onCreate()
方法中加载转换,如下所示:
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
Transition mTransition = //your transitions
getWindow().setSharedElementEnterTransition(mTransition);
getWindow().setSharedElementExitTransition(mTransition);