Question

I got this program that starts doing some tasks after I press the button, and it isn't allowed to change its orientation while this task is running. I got figured out how to do that, but my problem is that my code only works one way. It keeps succesully orientation in portrait while task is running and changes orientation to landscape only after task is completed (if user rotated device during task). But the same thing in landscape mode fails. It rotates to portrait even if task is running.

Here is the code that I use to keep orientation still. This code is in buttons onClick method:

final int ori = getResources().getConfiguration().orientation;
        setRequestedOrientation(ori);

then i have my handler class that checks every second if tasks have completed and if they are it gives my device premission to change orientation. To do this I use this code:

setRequestedOrientation(-1); // as far as I know -1 in this case means unspecified

I also have tried setRequestedOrientation(4); and setRequestedOrientation(10);

Was it helpful?

Solution

This answer has a lot of upvotes:

Background task, progress dialog, orientation change - is there any 100% working solution?

I think this is what you are looking for. A bit complicated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top