Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

I used a fragment in TabLayout to start a Youtube video Intent. The App was working OK but Logcat showed this error. I found that I didn't release the thumbnail loaders after they are loaded or not(depending on valid video id). It resolved my issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top