0

I want to set screen orientation dynamically using a service that checks whether some requirements are met. If it's met it changes orientation to portrait or landscape dynamically. I don't want to use activity. There is already one post related to my question but the solution uses LinearLayout which returns always null in the service context. The link to the post: How can I globally force screen orientation in Android?

Do you have any suggestion how can I implement something like that?

Community
  • 1
  • 1
omersem
  • 564
  • 7
  • 21

1 Answers1

0

I found the root cause of the problem. I was trying to inflate a Linear Layout in the constructor of the service however the instance of service is created before actually an activity calls the service. So any UI interaction should be done after actually the service is binded. Then there is no null pointer exception occurs. Additionally there is no difference between activity and service while setting the orientation globally. This code works How can I globally force screen orientation in Android?

Community
  • 1
  • 1
omersem
  • 564
  • 7
  • 21