Android Youtube Player API activity finish and create
You can do following steps to ensure memory leak problem to get resolved:
- Use Application Context
- Create a class for example named
YoutubeMyAPI
which implementsYouTubePlayer.OnFullscreenListener
- Create a class for example named
- create instance of that
YoutubeMyAPI
inApplication
Class
- create instance of that
- Wherever you are passing
onInitializedListener
pass instance ofYoutubeMyAPI
by getting((MyApp)getApplicationContext()).instanceOfYoutubeMyAPI
Hopefully you got the general idea to implement this obviously this is just a workaround there are better ways to do this...
I know this is not a propper answer to your question but around 10 months ago I struggled with the YoutubeAPI myself. I really wanted to use the propper YoutubeAPI from google because thats the official API and beause of future support, it being made inhouse and so on.
After facing many challenges such as your own I finally gave another third party library a chance and it was night and day
com.pierfrancescosoffritti.androidyoutubeplayer
this is the name of the depencency by pier francesco soffritti and if you continue facing challanges I seriously recommend you to give it a try. When I tried using the YoutubeAPI it hadnt been maintained for several years and I read about and personally faced bugs everywhere.
Here an article written by the man himself about why a third party library is the way to go here.