IllegalStateException一旦设置便无法更改活动类型

时间:2019-03-05 15:04:45

标签: android illegalstateexception

我可以看到在多个设备上引发了异常,但使用该异常的字符串从Google测试类中找不到任何异常。 您有什么暗示为什么会发生这种情况吗?

Fatal Exception: java.lang.IllegalStateException: Can't change activity type once set: { mBounds=Rect(0, 0 - 1080, 2076) mAppBounds=Rect(0, 0 - 1080, 2076) mWindowingMode=fullscreen mActivityType=home} activityType=standard
       at android.os.Parcel.createException(Parcel.java:1974)
       at android.os.Parcel.readException(Parcel.java:1934)
       at android.os.Parcel.readException(Parcel.java:1884)
       at android.app.IActivityManager$Stub$Proxy.startActivity(IActivityManager.java:3604)
       at android.app.Instrumentation.execStartActivity(Instrumentation.java:1669)
       at android.app.Activity.startActivityForResult(Activity.java:4688)
       at android.support.v4.app.FragmentActivity.startActivityForResult(SourceFile:767)
       at android.app.Activity.startActivityForResult(Activity.java:4646)
       at android.support.v4.app.FragmentActivity.startActivityForResult(SourceFile:754)
       at android.app.Activity.startActivity(Activity.java:5007)
       at android.app.Activity.startActivity(Activity.java:4975)
       at com.myapp.MyActivity.showAndroidHomeScreen(SourceFile:208)
       at com.myapp.MyActivity.onBackPressed(SourceFile:548)
       at android.app.Activity.onKeyUp(Activity.java:3168)
       at android.view.KeyEvent.dispatch(KeyEvent.java:3374)
       at android.app.Activity.dispatchKeyEvent(Activity.java:3451)
       at android.support.v4.app.SupportActivity.superDispatchKeyEvent(SourceFile:108)
       at android.support.v4.view.KeyEventDispatcher.dispatchKeyEvent(SourceFile:84)
       at android.support.v4.app.SupportActivity.dispatchKeyEvent(SourceFile:126)
       at android.support.v7.app.AppCompatActivity.dispatchKeyEvent(SourceFile:535)
       at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(SourceFile:59)
       at android.support.v7.app.AppCompatDelegateImpl$AppCompatWindowCallback.dispatchKeyEvent(SourceFile:2533)
       at com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:564)
       at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:6012)
       at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5867)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5320)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5373)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5339)
       at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5498)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5347)
       at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5555)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5320)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5373)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5339)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5347)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5320)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5373)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5339)
       at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5531)
       at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:5700)
       at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:3407)
       at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:2854)
       at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:2845)
       at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:3384)
       at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:326)
       at android.os.Looper.loop(Looper.java:181)
       at android.app.ActivityThread.main(ActivityThread.java:6981)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)

Caused by android.os.RemoteException: Remote stack trace:
    at android.app.WindowConfiguration.setActivityType(WindowConfiguration.java:366)
    at android.app.WindowConfiguration.setTo(WindowConfiguration.java:390)
    at android.content.res.Configuration.setTo(Configuration.java:1136)
    at com.android.server.wm.ConfigurationContainer.onConfigurationChanged(ConfigurationContainer.java:124)
    at com.android.server.wm.ConfigurationContainer.onParentChanged(ConfigurationContainer.java:523)

这是引起问题的代码:

 private void showAndroidHomeScreen() {
        final Intent mainScreen = new Intent(Intent.ACTION_MAIN);
        mainScreen.addCategory(Intent.CATEGORY_HOME);
        mainScreen.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        PackageManager pm = getPackageManager();
        if (pm.queryIntentActivities(mainScreen, 0).size() > 0) {
            startActivity(mainScreen);
        }
    }

1 个答案:

答案 0 :(得分:0)

这是启动器问题。只需与其他启动器确认 根本原因,因为启动器正在使用LaunchMode =“ singleInstance”作为启动器活动,所以发生了。如果是您的启动器,请使用android:launchMode =“ singleTask”。 也尝试删除

mainScreen.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)

希望有帮助。

更新 更新了android:launchMode =“ singleTask”进行默认需要设置的活动,它将解决您的问题。 无需使用FLAG_ACTIVITY_NO_HISTORY。