Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IllegalArgumentException in Shared Element Transition

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 ?

like image 378
cgr Avatar asked Oct 28 '22 23:10

cgr


1 Answers

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.

like image 136
ShahiM Avatar answered Nov 15 '22 06:11

ShahiM