How Android avoids the splash screen when switching to surfaceview (black screen Flash)

Source: Internet
Author: User

In recent projects, one activity has been used in Fragment+viewpager, and one of the fragment implements the video playback function, including Surfaceview. As a result, each time the program is opened the first time it enters the activity, it will splash the screen black. The reason is Surfaceview.

Detailed

I think I found the reason for the black Flash. In my case I ' m using a surfaceview inside a Fragment and dynamically adding this Fragment to the activity after some actio N. The moment when I add the fragment to the activity, the screen flashes black. I checked out Grepcode for the Surfaceview source and here's what I found:when the surface view appears in the window the Very fist time, it requests the window ' s parameters changing by calling a private Iwindowsession.relayout (..) method. This method "gives" you a new frame, window, and window surface. I think the screen blinks right at that moment.
The solution is pretty simple:if your window already have appropriate parameters it won't refresh all the window ' s stuff and the screen would not blink. The simplest solution is to add a 0px height plain surfaceview to the first layout of your activity. This would recreate the window before the activity is shown on the screen, and if you set your second layout it would just Continue using the window with the current parameters. I hope this helps.

Reason:

Surfaceview because it is different from the general view, it has its own good buffering and data access mechanism, the system has special treatment for him. When Surfaceview the first time in the current activity add, the system will give WindowManager layout, relayout, so it will be black, this will only appear in the first time, and then add Surfaceview will not be black screen.

Solve:

Can be in the interface without entering the Surfaceview (such as a lot of programs in the loading interface), In other interface Layout.xml file add a surfaceview, width and height are made into 0DP, so that the layout has no impact, and this thing makes Surfaceview first appeared, then that is, the next time we really use the surfaceview will not splash screen.

How Android avoids the splash screen when switching to surfaceview (black screen flash)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.