how to stop activity recreation on screen orientation?

后端 未结 7 603
情话喂你
情话喂你 2020-12-10 06:25

how i can stop the restarting or recalling of on create() on screen orientation ,i want to stop the recreation of activity on screen orientation. thanks in advance please te

7条回答
  •  醉酒成梦
    2020-12-10 06:50

    This is happening because when screen orientation rotates the Activity gets re-started. In this case you can add configChanges attribute in your tag in the AndroidManifest file to stop the re-creation of the Activity.

    
    

    By, this also it won't stop though the orientation changes.

    @Override
        public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);
            if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
                setContentView(R.layout.login_landscape);
            }
            else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
                setContentView(R.layout.login);         
            }
        }
    

提交回复
热议问题