Basically what the title says,
My application consists primarily of a ViewPager
which uses a FragmentStatePagerAdapter
The problem occurs when I add a series of SurfaceViews
to the FragmentStatePagerAdapter.
Just for testing purposes I did not subclass the SurfaceViews in any way.
When I navigate a few pages in, hit "home," and then return to the activity, the entire device freezes for a second or two before rendering anything. I can launch and finish() the app several times in the time it takes for it to resume after being pulled off of the backstack. I know that the application is running because several AsyncTasks have nearly finished by the time the first screendraw finally occurs. I know that these AsyncTasks do not cause the problem because I have removed them to no effect.
When I change the SurfaceViews to Views
the problem vanishes entirely.
This problem occurs when I use my actual SurfaceViews (which are non-negotiable for my project) as well. This problem also occurs on multiple devices.
At this point I think the fault lies squarely on the ViewPager, but I don't know what to do about it because I need that interface component.
Any help would be greatly appreciated!
EDIT:
To clarify, the SurfaceViews/Views represent the View of the Fragment which was added to the FragmentStatePagerAdapter.
Found the solution for any future googlers!
Heres how I did it:
In my fragment I instantiated mySurfaceView in onCreate()
Then I attached a dummy layout (LinearLayout) to the actual view during onCreateView()
Then in onResume() I cleared the dummy layout with removeAllViews() and then called addView(mySurfaceView)
This seems to allow the ViewPager to build its layout quickly and then the SurfaceView is just popped in before the user actually needs to see anything!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With