Logs , methods doesn't work when screen is rotate landscape

45 views Asked by At

I'm creating an app, which requires landscape / portrait screen. My problem is, when screen is rotate , the method doesn't work even the logger , so i'm having a hard time trouble shooting things. Anyone who have experience same? What i received in logs after rotation is

12-28 00:02:55.897 13039-13039/com.xxx.xxx D/ViewRootImpl: ViewPostImeInputStage processPointer 0
12-28 00:02:55.927 13039-13039/com.xxx.xxx D/ViewRootImpl: ViewPostImeInputStage processPointer 1

In here, i'm trying to load a different XML when user is in landscape or portrait. I'm using this method because, i have additional controls when in landscape mode, and those controls are not available during portrait mode. so i need to call bindNewControlsLoaded() method to initialize those controls.

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            setContentView(R.layout.activity_task_page_lan);
            initCreate();
            //im calling this because some controls are newly added
            bindNewControlsLoaded();
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            setContentView(R.layout.activity_task_page);
            initCreate();
        }

    }

initCreate method is a method for portrait , this is use to load common controls. while additional controls are called in the bindNewControlsLoaded();

In my manifest android:configChanges="orientation|screenSize"

1

There are 1 answers

2
Anton Pogonets On

By default android recreate activity on rotate so you can do it without onConfigurationChanged at all just use resource qualifiers . In your case just move activity_task_page_lan.xml to res/layout-land/ folder and rename to activity_task_page.xml.

But if you really want to handle this case with your code and prevent activity recreation you should add android:configChanges="orientation" to activity declaration.