You can follow the logic below to prevent auto rotate screen while your AsyncTask
is running:
getRequestedOrientation()
.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR)
.AsyncTask
.AsyncTask
restore your previous orientation status using setRequestedOrientation(oldOrientation)
.Please note that there are several ways to access Activity
(which runs on UI thread) properties inside an AsyncTask
. You can implement your AsyncTask
as an inner class or you can use message Handler
that poke your Activiy
class.