2

After updating to API 27 and Support library 27.0.2 suddenly I get a lot of these stack traces in Crashlytics:

Fatal Exception: java.lang.IllegalArgumentException
    at android.os.Parcel.readException(Parcel.java:1544)
    at android.os.Parcel.readException(Parcel.java:1493)
    at android.app.ActivityManagerProxy.isTopOfTask(ActivityManagerNative.java:5108)
    at android.app.Activity.isTopOfTask(Activity.java:5688)
    at android.app.Activity.startActivityForResult(Activity.java:3973)
    at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(Source:54)
    at android.support.v4.app.FragmentActivity.startActivityForResult(Source:67)

I call this like:

ActivityOptions options = ActivityOptions.makeCustomAnimation(activity, R.anim.slide_in_from_right, R.anim.fade_out);
startActivityForResult( intent, REQ_ACTION, options.toBundle());

I cannot read the source code as it is not released yet. I even tried to replace and use android-26 code, but it's different.

There is a warning for the above call saying that BaseFragmentActivityApi16.startActivityForResult can only called from the same library group, so I fixed it by using ActivityCompat, but I don't think it will solve the crash problem.

Is this a platform issue or can I fix this?

Edit

if (Build.VERSION.SDK_INT >= 21) {
    ActivityOptions options = ActivityOptions.makeCustomAnimation(activity, R.anim.slide_in_from_right, R.anim.fade_out);
    startActivityForResult(intent, REQ_ACTION, options.toBundle());
} else {
    ActivityOptions options = ActivityOptions.makeCustomAnimation(activity, R.anim.slide_in_from_right, R.anim.fade_out);
    ActivityCompat.startActivityForResult(this, intent, REQ_ACTION, options.toBundle());
}

If I change it to the above according to the link in my comment, Android Studio complaining like above. This might be related to the problem.

Herrbert74
  • 2,578
  • 31
  • 51
  • You might be running into this https://stackoverflow.com/q/47257407/8298909 (closed since it's basically a tech support question) – Ben P. Dec 04 '17 at 18:31
  • @BenP. That looks a completely different issue, accidentally involving Parcelables as well. – Herrbert74 Dec 07 '17 at 10:40
  • It looks more like an animation and support library issue to me. 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. I think it's still using the wrong version somehow. I updated the question with the animation option. – Herrbert74 Dec 07 '17 at 10:46
  • startActivity(intent, options.toBundle()); This is what i'm using in my application – Muhammad Saad Dec 07 '17 at 11:11
  • @MuhammadSaad This might solve the problem, but I don't want to throw the baby out with the bathwater. I need the result, you know. – Herrbert74 Dec 07 '17 at 11:14

3 Answers3

2

You can try this code.

startActivityForResult( intent, REQ_ACTION)
overridePendingTransition(R.anim.slide_in_from_right,  R.anim.fade_out);
Muhammad Saad
  • 713
  • 1
  • 9
  • 31
1

Old post but unanswered, so here what I found in 21+

Make sure you are looking for startActivityForResult under activity object. Under Context object you can find startActvity but you will not see startActivityForResult method.

If your context is Context class but is an activity then make sure you cast it to Activity.

Context context = ...;
context.startActivityForResult(...); // this method will not exist
((Activity)context).startActivityForResult(...); // this method should be ok
Zunair
  • 1,085
  • 1
  • 13
  • 21
  • This removed the warning from the IDE. But not sure this will solve the crash. I will wait for some days. Thanks. I am using 27.1.0 and crash is from 6.0.1 – Aram Dec 12 '18 at 06:40
0

Use ActivityOptionsCompat instead of ActivityOptions for below api 21.

ActivityOptionsCompat is a helper class for accessing features in ActivityOptions in a backwards compatible fashion.

if (Build.VERSION.SDK_INT >= 21) {
  ActivityOptions options = ActivityOptions.makeCustomAnimation(activity, 
  R.anim.slide_in_from_right, R.anim.fade_out);
  startActivityForResult(intent, REQ_ACTION, options.toBundle()); 
  } else {
   ActivityOptionsCompat options = ActivityOptionsCompat
  .makeCustomAnimation(activity,R.anim.slide_in_from_right,R.anim.fade_out);
   ActivityCompat.startActivity(this, intent, options.toBundle());
}

Hope this will help you.

Vishal Chauhan
  • 932
  • 1
  • 6
  • 11