79

There is a crash in my app on devices running version 7.0, 7.1.1 and 8.0.0 with the following stacktrace:

Fatal Exception: java.lang.RuntimeException: Unable to resume activity {xxx/xxx.views.activities.HomeActivity}: java.lang.IllegalArgumentException
   at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3788)
   at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3828)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2991)
   at android.app.ActivityThread.-wrap14(ActivityThread.java)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6692)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by java.lang.IllegalArgumentException
   at android.os.Parcel.readException(Parcel.java:1697)
   at android.os.Parcel.readException(Parcel.java:1646)
   at android.app.ActivityManagerProxy.isTopOfTask(ActivityManagerNative.java:6600)
   at android.app.Activity.isTopOfTask(Activity.java:6142)
   at android.app.Activity.onResume(Activity.java:1331)
   at android.support.v4.app.FragmentActivity.onResume(FragmentActivity.java:485)
   at xxx.views.activities.BaseActivity.onResume(BaseActivity.java:50)
   at xxx.views.activities.HomeActivity.onResume(HomeActivity.java:364)
   at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1277)
   at android.app.Activity.performResume(Activity.java:7058)
   at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3765)
   at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3828)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2991)
   at android.app.ActivityThread.-wrap14(ActivityThread.java)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6692)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)

My code on the reported lines is simply:

// HomeActivity class
@Override
public void onResume() {
    mPresenter.onResume();
    super.onResume();

    renderView();
}

// BaseActivity class
@Override
protected void onResume() {
    super.onResume();
    // some other code
}

I did some digging about this and found this similar question.

Since the IllegalArgumentException thrown contains no detail message, I am going to try putting in extra logs as suggested here.

Meanwhile please appreciate any help!

Hemant N. Karmur
  • 840
  • 1
  • 7
  • 21
Jiyeh
  • 5,187
  • 2
  • 30
  • 31
  • 1
    The super.onResume should be call first thing in your onResume method call. – JoxTraex Jan 02 '18 at 03:11
  • 1
    @JoxTraex onResume is the first thing in the onResume method. But it doesn't fix it. I am also facing same issue in my project. – Ani Jan 04 '18 at 05:59
  • Have you tested android L 5.1.x? – JoxTraex Jan 04 '18 at 06:56
  • Your stack trace also shows: `at xxx.views.activities.HomeActivity.onResume(HomeActivity.java:364)`. This is something custom? Looks like you didn't post all of the code you're using – milosmns Aug 24 '19 at 10:13

3 Answers3

2
            catch (Exception e) {
                if (!mInstrumentation.onException(r.activity, e)) {
                    throw new RuntimeException(
                        "Unable to resume activity "
                        + r.intent.getComponent().toShortString()
                        + ": " + e.toString(), e);
                }
            }

it's a chained exeption so inspect e.getCause() stacktrace -> till cause will be null

if you'll not find it look at the method in activity thread which invokes try block:

try {
  r.activity.onStateNotSaved();
  r.activity.mFragments.noteStateNotSaved();

  if (r.pendingIntents != null) {
    deliverNewIntents(r, r.pendingIntents);
    r.pendingIntents = null;
  }

  if (r.pendingResults != null) {
    deliverResults(r, r.pendingResults);
    r.pendingResults = null;
  }

  r.activity.performResume();

  // If there is a pending local relaunch that was requested 
  // when the activity was
  // paused, it will put the activity into paused state
  // when it finally happens.
  // Since the activity resumed before being relaunched, 
  // we don't want that to happen,
  // so we need to clear the request to relaunch paused.

  for (int i = mRelaunchingActivities.size() - 1; i >= 0; i--) {
    final ActivityClientRecord relaunching =
    mRelaunchingActivities.get(i);

    if (relaunching.token == r.token
        && relaunching.onlyLocalRequest &&
        relaunching.startsNotResumed) {
            relaunching.startsNotResumed = false;
    }
 }
}

you'll need to search for reason in:

  • Activity.onStateNotSaved();
  • Activity.mFragments.noteStateNotSaved();
  • Activity.performResume();
  • and final Activity.onNewIntent()
    Caused by java.lang.IllegalArgumentException
        at android.os.Parcel.readException(Parcel.java:1697)
        at android.os.Parcel.readException(Parcel.java:1646)
        at android.app.ActivityManagerProxy.isTopOfTask (ActivityManagerNative.java:6600)
        at android.app.Activity.isTopOfTask(Activity.java:6142)
        at android.app.Activity.onResume(Activity.java:1331)

and best shot it's an answer for this issue:

rjava.lang.IllegalArgumentException on startActivity(intent,bundle animantion)

Arjun Vyas
  • 409
  • 5
  • 14
ceph3us
  • 7,326
  • 3
  • 36
  • 43
-1

Problem is with you parcel. You need to find where activity, fragment, view is saving parcel to save state. There will be wrong sequence. e.g.

@Override
protected Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();

    final CharSequence textFromEditText = mTextView.getText();
    if (textFromEditText != null) {
        SavedState savedState = new SavedState(superState);
        savedState.text = textFromEditText.toString();
        return savedState;
    }
    return superState;
}

@Override
protected void onRestoreInstanceState(Parcelable state) {
    if (!(state instanceof SavedState)) {
        super.onRestoreInstanceState(state);
        return;
    }

    SavedState savedState = (SavedState) state;
    super.onRestoreInstanceState(savedState.getSuperState());
    if (!TextUtils.isEmpty(savedState.text)) {
        mTextView.setText(savedState.text);
    }
}

private static class SavedState extends BaseSavedState {
    String text;

    private SavedState(Parcelable superState) {
        super(superState);
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeString(text);
    }

    private SavedState(Parcel source) {
        super(source);
        text = source.readString();
    }

    public static final Creator<SavedState> CREATOR = new Creator<SavedState>() {

        @Override
        public SavedState createFromParcel(Parcel source) {
            return new SavedState(source);
        }

        @Override
        public SavedState[] newArray(int size) {
            return new SavedState[size];
        }
    };
}

so the problem could be somwhere in

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeString(text);
    }

    private SavedState(Parcel source) {
        super(source);
        text = source.readString();
    }

when the sequance of Parcel source reading are bad.

-1

I had also the same issue in my project. While researching I found that it might also be possible if you are trying to access any static variables or methods from your Activity's onResume() method.

Ishaan Javali
  • 1,711
  • 3
  • 13
  • 23
Ajay Mehta
  • 843
  • 5
  • 14