0

I am working on a camera application, but when I change the orientation the activity is rebuilt, the problem is that it takes about 2 seconds to start all over again and that looks very bad because there is a pause in the image, that's why I want it have a similar behavior to the default camera application that when rotating the screen simply rotates the icons, no unpleasant pauses are seen ...

I tried setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); but getResources().getConfiguration().orientation it always returns 1 (portrait), so I want something similar to the behavior of SCREEN_ORIENTATION_PORTRAIT which does nothing when rotating the screen.

But I need detect that the screen was rotated (so I can control what should happen)

JP711
  • 533
  • 6
  • 15

1 Answers1

1

You could handle configuration changes yourself by setting android:configChanges="orientation" in your activity in your manifest. Then your activity won't be destroyed when the screen is rotated. You can read more about configChanges here.

Then you can also override onConfigurationChanged to detect the rotation of the phone.

just_user
  • 11,769
  • 19
  • 90
  • 135
  • thanks for answering, I had tried but the result is the similarity there is a pause of 1 second this time it is not rebuilt but the content rotates, the main objective is that when rotating absolutely nothing happens, and to be able to control it myself – JP711 Sep 15 '20 at 15:20
  • Some other options are to set android:screenOrientation="portrait" on your activity in the manifest. Maybe it works with onConfigurationChanged, never tried. Or maybe you have two layouts defined? Landscape and portrait, if so try to delete the landscape one and see if that speeds things up! – just_user Sep 15 '20 at 15:24
  • None of that works but I found the answer [Here](https://stackoverflow.com/a/34970844/13452141), thanks for your help – JP711 Sep 15 '20 at 17:43