I want to use SurfaceView for animation to show the live camera preview. It is working fine. But when it loads for first time it flickering for first time.
Asked
Active
Viewed 1,798 times
2 Answers
6
This is common issue with android surface view.
Window was destroyed then re-created when the SurfaceView was adding, and the Window's pixel format was changed mean while, that guided me to the answer, the pixel format of the SurfaceView and the Activity was different so Window Manager forced the re-created.
To resolve it, just added one line in onCreate() to set pixel format, as below:
getWindow().setFormat(PixelFormat.TRANSLUCENT);

Amarjit
- 4,327
- 2
- 34
- 51

Sagar Panwala
- 922
- 1
- 8
- 23
-
This doesn't entirely make sense, as the buffer format for the camera preview will be YUV, so changing the window format from RGB565 to RGBA8888 shouldn't make a difference. But if it eliminates the blink, run with it. – fadden Sep 04 '15 at 16:13
1
Adding a 0px height blank surfaceView to the first layout of the activity might solve the issue. It is a crazy solution, but it solved the issue for me.
You could also check the following query which has a full explanation of answer. "SurfaceView flashes black on load"