2

I am using a viewpager with tab navigation for an Android project. One of my tabs has a surfaceview with a camera preview. The problem is that whenever I navigate to a neighboring tab, the preview in the camera tab starts even though the camera tab is not visible. Not only does this slow my app down, but if I then navigate to another tab and then to the camera tab, my app attempts to restart the preview thus resulting in a crash.

I'm looking for advice on how to only start a camera preview if the fragment is visible(ie. tab is active). And to finish preview as soon as tab is switched.

Thank you.

nyc0202034
  • 113
  • 1
  • 3
  • 14
  • 1
    I solved it with the help of this answer: http://stackoverflow.com/questions/24161160/setuservisiblehint-called-before-oncreateview-in-fragment#comment45069545_24934483 – nyc0202034 Feb 20 '15 at 07:46

0 Answers0