2
\$\begingroup\$

When I create SurfaceView for first time since app launch, the app screen blinks black for small time (about 1/4 second). It blinks over UI, so its really visible and doesn't look nice at all. I've tried to comment all of my code in surfaceCreated, but effect is same, so problem is not here. How do I remove or "hide" this screen blink?

In activity:

RelativeLayout layout = (RelativeLayout) findViewById(R.id.relative);
layout.addView(new Surface(getApplicationContext())); // causes short screen black blink

Surfaceview class:

public class Surface extends SurfaceView implements SurfaceHolder.Callback
{
        public Surface(Context context)
        {
            super(context);
 
            getHolder().addCallback(this);
            this.setZOrderOnTop(true);
            getHolder().setFormat(PixelFormat.TRANSPARENT);
            setFocusable(true);
        }
    
        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
        {
        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder)
        {
        }

        @Override
        public void surfaceCreated(SurfaceHolder holder)
        {
              ... stuff
        }
}
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Alright, after 2 hard-thinking days I've found quite a good workaround. Didn't fixed that blink, but it's hidden very well. Here's how to:

Create another Surfaceview class, for example FakeSurfaceview.java. Keep same options for it as I mentioned in SF class in main post. In surfaceCreated, add this.setVisibility(GONE);

In you main layout (first layout when your app launches), create RelativeLayout with width and height 0dp.

<RelativeLayout
        android:id="@+id/setupRelative"
        android:layout_width="0dp"
        android:layout_height="0dp">
</RelativeLayout>

At app start, after you set view to your main layout, create this fake Surfaceview:

RelativeLayout setupLayout = (RelativeLayout) findViewById(R.id.setupRelative);
setupLayout.addView(new FakeSurfaceview(getApplicationContext()));

That's it. Now, creating this FakeSurfaceview will blink, but nobody will notice it because it'll create durring app start (best with combination of startup black activity color!). Then, when you create anytime another SurfaceView, no blink will apear. That's it!

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .