问题描述
我可以看到在多个设备上引发了异常,但使用该异常的字符串从Google的测试类中找不到任何异常.您有什么暗示为什么会发生这种情况吗?
I can see an exception being thrown on multiple devices for which I could not find anything beside tests classes from Google using that exception's string.Would you have any hint why this could be happening?
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);
}
}
推荐答案
这是启动器问题.只需与其他启动器进行检查根本原因,因为启动器正在使用launchMode ="singleInstance",因为它是启动器活动.如果是您的启动器,请使用android:launchMode ="singleTask".也尝试删除
It's launcher problem. Just check with different launcherRoot cause it is happening because launcher is using launchMode="singleInstance" for it's Launcher Activity. if it's your launcher then use android:launchMode="singleTask".also try with removing
希望有帮助.
更新更新了android:launchMode ="singleTask"对于您需要默认设置的活动,它将解决您的问题.无需使用FLAG_ACTIVITY_NO_HISTORY.
UPDATEupdated android:launchMode="singleTask" for activity that you need yo set up for default, it will fixed your issues.no need to use FLAG_ACTIVITY_NO_HISTORY.
这篇关于IllegalStateException一旦设置便无法更改活动类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!