I'm using an Activity that has a layout with android.support.v4.view.ViewPager that I used to manipulate Tab navigation. I have different Fragments for different Tabs. On my third Tab, I'm loading some YouTube thumbnails from my YouTube account.
When I load the application (when I'm staying at the first Tab) and press Back to exit from the application, it exists without any issue. But when I navigate to second Tab and try to press Back button, app exists with an error as follow.
E/ActivityThread(7187): Activity package.name.ActivityName has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@41e5d180 that was originally bound here
E/ActivityThread(7187): android.app.ServiceConnectionLeaked: Activity package.name.ActivityName has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@41e5d180 that was originally bound here
I've added YouTube Data API v3 to my project.
How can I solve this issue? Why the error appears when exiting from second Tab but not in First Tab?
This is not a duplicate question of this.
If I guess it correctly, you load the api when the second page appears, and also then init the YouTube API. Instead of supplying your activity as the context try supplying the application context to the api.