java.lang.RuntimeException:无法使用java.lang.IllegalArgumentException恢复活动

时间:2021-07-29 16:51:22

Recently I sometimes got this exception when MainActivity called onResume().

最近,当MainActivity调用onResume()时,我有时会遇到此异常。

java.lang.RuntimeException: Unable to resume activity {com.qau4d.c35s3.androidapp/com.xxx.XXX.XXX.MainActivity}: java.lang.IllegalArgumentException
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3400)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3440)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1510)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.IllegalArgumentException
at android.os.Parcel.readException(Parcel.java:1687)
at android.os.Parcel.readException(Parcel.java:1636)
at android.app.ActivityManagerProxy.isTopOfTask(ActivityManagerNative.java:5475)
at android.app.Activity.isTopOfTask(Activity.java:5961)
at android.app.Activity.onResume(Activity.java:1252)
at com.qau4d.c35s3.androidapp.onResume(XActivity.java:29)
at com.qau4d.c35s3.androidapp.onResume(MainActivity.java:196)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1269)
at android.app.Activity.performResume(Activity.java:6768)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3377)

Both in MainActivity and super class XActivity, only super.onResume(); . It's really strange to get this exception after a long time normal development.I checked some relative reference material but nothing got.

在MainActivity和超类XActivity中,只有super.onResume(); 。经过长时间的正常开发后得到这个异常真的很奇怪。我查了一些相关的参考资料但没有得到。

2 个解决方案

#1


5  

There is insufficient information in your question to determine the cause of the java.lang.IllegalArgumentException, Unfortunately the android ActivityThread doesn't log the stacktrace of that exception, and the exception message appears to be empty.

您的问题中没有足够的信息来确定java.lang.IllegalArgumentException的原因,不幸的是,android ActivityThread不记录该异常的堆栈跟踪,并且异常消息似乎为空。

However, it looks like there is a way forward. The exception is handled by the following code in the ActivityThread::performResumeActivity method:

但是,看起来还有一条前进的道路。该异常由ActivityThread :: performResumeActivity方法中的以下代码处理:

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

If you register1 an instrumentation class for your activity, it should be possible to use an onException method to log the stacktrace for the causal exception.

如果为活动注册1一个检测类,则应该可以使用onException方法记录因果异常的堆栈跟踪。

This won't solve the problem (!) but it will get you a step closer to a solution.

这不会解决问题(!),但它会让您更接近解决方案。


1 - Google for "Android instrumentation onException".

1 - Google for“Android instrumentation onException”。

#2


3  

In the method Activity#isTopOfTask we can see:

在方法Activity#isTopOfTask中我们可以看到:

private boolean isTopOfTask() {
    if (mToken == null || mWindow == null) {
        return false;
    }
    try {
        return ActivityManager.getService().isTopOfTask(getActivityToken());
    } catch (RemoteException e) {
        return false;
    }
}

And in ActivityManagerService#isTopOfTask we can found:

在ActivityManagerService#isTopOfTask中我们可以找到:

@Override
public boolean isTopOfTask(IBinder token) {
    synchronized (this) {
        ActivityRecord r = ActivityRecord.isInStackLocked(token);
        if (r == null) {
            throw new IllegalArgumentException();
        }
        return r.task.getTopActivity() == r;
    }
}

So, I think that ActivityRecord is null.But I don't know why it is null....

所以,我认为ActivityRecord是null。但我不知道为什么它是null ....

#1


5  

There is insufficient information in your question to determine the cause of the java.lang.IllegalArgumentException, Unfortunately the android ActivityThread doesn't log the stacktrace of that exception, and the exception message appears to be empty.

您的问题中没有足够的信息来确定java.lang.IllegalArgumentException的原因,不幸的是,android ActivityThread不记录该异常的堆栈跟踪,并且异常消息似乎为空。

However, it looks like there is a way forward. The exception is handled by the following code in the ActivityThread::performResumeActivity method:

但是,看起来还有一条前进的道路。该异常由ActivityThread :: performResumeActivity方法中的以下代码处理:

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

If you register1 an instrumentation class for your activity, it should be possible to use an onException method to log the stacktrace for the causal exception.

如果为活动注册1一个检测类,则应该可以使用onException方法记录因果异常的堆栈跟踪。

This won't solve the problem (!) but it will get you a step closer to a solution.

这不会解决问题(!),但它会让您更接近解决方案。


1 - Google for "Android instrumentation onException".

1 - Google for“Android instrumentation onException”。

#2


3  

In the method Activity#isTopOfTask we can see:

在方法Activity#isTopOfTask中我们可以看到:

private boolean isTopOfTask() {
    if (mToken == null || mWindow == null) {
        return false;
    }
    try {
        return ActivityManager.getService().isTopOfTask(getActivityToken());
    } catch (RemoteException e) {
        return false;
    }
}

And in ActivityManagerService#isTopOfTask we can found:

在ActivityManagerService#isTopOfTask中我们可以找到:

@Override
public boolean isTopOfTask(IBinder token) {
    synchronized (this) {
        ActivityRecord r = ActivityRecord.isInStackLocked(token);
        if (r == null) {
            throw new IllegalArgumentException();
        }
        return r.task.getTopActivity() == r;
    }
}

So, I think that ActivityRecord is null.But I don't know why it is null....

所以,我认为ActivityRecord是null。但我不知道为什么它是null ....