10

Issue: ActivityA starts ActivityB with shared element transitions intermittently crashes Not consistently reproducible Api levels: 23, 24 and 25

Code to launch activity:

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)

Does anyone know what causes this behaviour? Any proposed fix for this?

Gabor Peto
  • 642
  • 11
  • 24

3 Answers3

5

I suppose, you should not use methods from support library for that versions. Sure, I can't figure out, from your existing issue due of random stacktrace.

Since Tranlsation Scene introduced form 4.4. You can include api deprecation. Moreover, it's recommended, otherwise, why we need both types?

 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());
    }
GensaGames
  • 5,538
  • 4
  • 24
  • 53
  • 3
    I thought the whole purpose of ActivityCompat is that you don't have to check SDK version to apply new functionalities. How confident are you that this would solve my problem? – Gabor Peto Feb 25 '17 at 14:54
  • 1
    @GaborPeto For ActivityCompat yes, but not for options type ActivityOptionsCompat. – GensaGames Feb 25 '17 at 18:40
  • @GensaGames I still get the same exception with the same code above on Lollipop devices. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ActivityOptions options = ActivityOptions .makeSceneTransitionAnimation(MyActivity.this, logoImageView, "transition_name"); startActivity(intent, options.toBundle()); } Exception happens at startActivity(). – cgr Nov 02 '17 at 07:05
  • 1
    I get the same exception, same stack trace down to Activity.startActivity, I have no AppCompat on the stack – androidguy Nov 12 '17 at 04:35
  • @user3175580 Do you have additional steps to check it? – GensaGames Nov 14 '17 at 15:14
  • @GensaGames can you clarify? I don't know yet what causes this. I just saw this reported in Play Console crash reports for the first time (out of like 50 users, so not a good sign). The device it happend on had Android 7 and 4GB RAM. The Android source code suggests, in Parcel#writeNoException, that there were "StrictMode violations" `if (StrictMode.hasGatheredViolations()) ....`. There is a note in the comments of android.os.StrictMode: "so you should never leave StrictMode * enabled in applications distributed on Google Play" – androidguy Jan 14 '18 at 22:39
3

in my case this happen because i subscribe on click action two times, so startActivity was called twice in a row.

hope this can be helpful for some one :)

Andriy Antonov
  • 1,360
  • 2
  • 15
  • 29
0

Try loading transitions in the onCreate() method of the concerned activity like this:

getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);

Transition mTransition = //your transitions
getWindow().setSharedElementEnterTransition(mTransition);
getWindow().setSharedElementExitTransition(mTransition);
Abdul Wasae
  • 3,614
  • 4
  • 34
  • 56