1

Getting an IllegalArgumentException when starting an activity with a bundle like this:

val intent = Intent(this, IntroActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
val bundle = ActivityOptionsCompat.makeCustomAnimation(this, R.anim.fade_in_activity, R.anim.fade_out_activity).toBundle()
startActivity(intent, bundle)

The main problem is that this doesn't occur on all devices. So far, from 100+ devices, got it on around 20 or so.

I'm getting the following stacktrace:

Fatal Exception: java.lang.IllegalArgumentException
       at android.os.Parcel.readException(Parcel.java:1722)
       at android.os.Parcel.readException(Parcel.java:1671)
       at android.app.ActivityManagerProxy.isTopOfTask(ActivityManagerProxy.java:5573)
       at android.app.Activity.isTopOfTask(Activity.java:6151)
       at android.app.Activity.cancelInputsAndStartExitTransition(Activity.java:4440)
       at android.app.Activity.startActivityForResult(Activity.java:4417)
       at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:767)
       at android.app.Activity.startActivity(Activity.java:4691)
       at [...].splash.SplashActivity.continueToIntro(SplashActivity.java:428)

I saw a similar question here: rjava.lang.IllegalArgumentException on startActivity(intent,bundle animantion) But unfortunately I am already using ActivityOptionsCompat.

It's happening on Android api 23+.

Did anyone get this and did you manage to fix it?

Adrian Coman
  • 1,536
  • 17
  • 30
  • Those seem like an unusual set of flags to put on an `Intent`. What is your objective behind those flags? – CommonsWare May 13 '19 at 12:18
  • Which one does `intent.flags` refer to? IMHO, you might need to use `addFlags` instead of `setFlags`. – nuhkoca May 13 '19 at 12:38
  • Never thought that the problem was from the flags, tbh. The flags needed are probably just these: `Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK` as i'm trying to clear all the stack of activities so the user can't press back and get to the previous one. – Adrian Coman May 13 '19 at 13:19
  • Im im currently facing the same Error. Does it help to change that Flags? – Flo rian Oct 28 '20 at 07:19
  • As https://stackoverflow.com/questions/11308198/start-new-activity-and-finish-current-one-in-android you can disable a history on that activity – Flo rian Oct 28 '20 at 07:22

0 Answers0