IllegalStateException Can't change activity type once set
Asked Answered
A

2

22

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)

This is the code causing the issue:

 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);
        }
    }
Algy answered 5/3, 2019 at 15:4 Comment(4)
Did you solve it? I also face this problem while I want to show launcher selection picker.Thinking
No, it still happens.Algy
Did u found any solution for this ?Lamaism
@Algy are you still facing issues post updating launch mode singleTask for launcher activity? it is fixed for me it was reproducible in Nokia2.3/10.Goldfarb
G
2

It's launcher problem. Just check with different launcher Root 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

mainScreen.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)

Hope it helps.

UPDATE updated 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.

Goldfarb answered 19/2, 2020 at 7:13 Comment(6)
Are you sure about that? How did you find out? And no, it's not my launcher, I'm only making sure I exit my own app launching the launcher.Algy
Yes, you face this issue in android 10 devices only. right?Goldfarb
I'm not sure now, would need to search for the issue on crashlytics, I think it's not 10-only.Algy
This doesn't work for me as i don't have this flag insead i have setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);Lamaism
@DeepakRajput can you please cross check launchMode of your activity.Goldfarb
@Algy is it happening for you with your custom launcher or system launcher?Goldfarb
C
0

The launcher activity's default launch mode is singleTask, you can remove Intent.FLAG_ACTIVITY_NO_HISTORY can try again, can't override launch mode in intent.

Cerumen answered 28/9, 2022 at 3:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.