Lock orientation until Asynctask finish

前端 未结 3 1684
别跟我提以往
别跟我提以往 2021-02-08 10:41

Only want to block orientation until all the data is loaded in my view. So I thought about the following code but it doesn\'t work.

private class task extends As         


        
3条回答
  •  情歌与酒
    2021-02-08 11:07

    Just replace setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); with setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);

    And let me know what happen..

    For Entry Level

     protected void onPreExecute() {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
    }
    

    At Exit Level

     protected void onPostExecute(String result) {
          ...
         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
       }
    

    Update:

    Wired behavior (In your case) but, any way you can get the current orientation using,

    int currentOrientation = getResources().getConfiguration().orientation; 
    

    Now set this orientation in onPreExecute() ..

    Like,

    protected void onPreExecute() {
      ...
      int currentOrientation = getResources().getConfiguration().orientation; 
       if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
       }
       else {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
       }
    }
    

    Simple.. :-)

提交回复
热议问题