Lock orientation until Asynctask finish

前端 未结 3 1689
别跟我提以往
别跟我提以往 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:05

    You are doing this because you have found that your async task is killed during the activity destroy and recreate. Am I right?

    The correct way of handling this is not to lock the orientation whilst your task is running. I don't agree that the setRequestedOrientation approach not working is a bug; rather the idea of locking an activities orientation and then unlocking from an async task is unsupported.

    I have gone to explain in some detail how to ensure your async task is not killed by disassociating it with your activity lifecycle. Looking back on the solution I provided I have since discovered better ways of checking a service is running (Inter Process Control and bound services) but the overarching principle applies. Host the async task in an orientation unaware android.app.Service and allow the async task to only communicate with the service and the service to only communicate with those activities which have bound to it.

    I think this is a more standard approach.

提交回复
热议问题