Capture orientation change event before it happens

前端 未结 2 688
甜味超标
甜味超标 2021-01-28 04:30

It\'s simple to lock the orientation to portrait or landscape.


         


        
2条回答
  •  面向向阳花
    2021-01-28 04:59

    Use this piece of code in onPause() method. When rotatio changes, activty re-coustructs it self which means on-Create is called again and previous activity is finish();

        int currentOrientation = getResources().getConfiguration().orientation;
        if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE){
            if (display.getRotation() == Surface.ROTATION_0)
            // play with different angles e.g ROTATION_90, ROTATION_180
        }
    

    So when rotation changes the previous activites's onPause() will be called and at that stage you can decide what you want with new orientation.

提交回复
热议问题