I'm trying to build a custom camera app. I have a class which extends SurfaceView for the camera preview. When the device changes orientation, this surface is destroyed and recreated, leading to a noticeable "glitch" which diminishes user experience.
What I'd like to do is to prevent this camera preview from having to be recreated on orientation change. In addition, I'd like to have some buttons overlaying this preview (e.g. flash, choice of front/back camera etc.) which WOULD rotate on orientation change. This is similar to what the stock camera app does:
Stock camera in landscape mode.
Stock camera in portrait mode. Note that buttons rotate on orientation change.
Best approach I found (described, for example, here) is to force the activity orientation to landscape using the manifest file and, once the picture is taken, rotate the resulting picture depending on the real device orientation. The drawback of this approach, as I understand it, is that this will prevent rotation of the overlaying buttons as well. Alternatively, as I've read a bit about using fragments and retaining fragment instances, I am wondering whether I could accomplish my goal by retaining the fragment containing the camera preview (yes, I'm a noob).
What would be the proper way to do this?