Android Device onConfigurationChanged event does not handling orientation

前端 未结 3 1251
执念已碎
执念已碎 2021-01-13 18:46

i have an activity and on startup of the activity i need to change the orientation in lanscape and then later on i want to handle both orientation changes as user rotates de

3条回答
  •  伪装坚强ぢ
    2021-01-13 19:16

    I'm not clear about your requirement. If you don't mind restarting your activity, you can just skip overriding onConfigurationChanged. System will handle Orientation changes for you. In case you don't want it to be restarted on orientation changes, just mention , and override onConfigurationChanged and call setContentView()

    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        setContentview(R.layout.activity_hls);
        initializeViews();//here you can initialize all your memberVariables using findViewbyID()
    }
    

提交回复
热议问题