Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IllegalStateException Can't change activity type once set

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);
        }
    }
like image 421
David Avatar asked Mar 05 '19 15:03

David


1 Answers

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.

like image 69
Imtiyaz Khalani Avatar answered Nov 07 '22 16:11

Imtiyaz Khalani