Android Device onConfigurationChanged event does not handling orientation

前端 未结 3 1284
执念已碎
执念已碎 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:21

    On this statement

    if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
        {
            Toast.makeText(this, "portrait", Toast.LENGTH_LONG).show();
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
        {
            Toast.makeText(this, "landscape", Toast.LENGTH_LONG).show();
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } 
    

    also in onCreate(Bundle bundle);

    You called

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    

    or

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    

    It means that your activity is in landscape/portrait orientation and never rotate again

    removing it will trigger the onConfigurationChanged(Configuration) again

提交回复
热议问题