Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YouTubePlayerSupportFragment starts duplicate Activity

I am using a YouTubePlayerSupportFragment to embed a YouTube video in my app. When embedded it works very well, the video plays, everything is great.

When I tap the Fullscreen button my embedded YouTube video fragment, the first strange thing happens: It instantiates a new copy of the existing enclosing Activity... and I have no idea why.

I have one Activity, RootActivity, which displays several fragments in a ViewPager. The fragment I'm dealing with at the moment is called EasyModePurchaseFragment. That EMPF has the YouTubePlayerSupportFragment embedded in its layout xml:

<fragment
    android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
    android:id="@+id/youtube_fragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
/>

When I tap the Fullscreen button on the YouTubePlayerSupportFragment, an entirely new RootActivity gets instantiated. Why is that?

It's causing me some problems because it doesn't get fully created in the proper way, which means it causes a crash.. and it's no good.

EDIT:

I've also tried intercepting the onFullScreen() event and instead of resizing the view, I just attempt to launch a standalone YouTube player with their provided intents:

Intent intent = YouTubeStandalonePlayer.createVideoIntent(getActivity(), myDeveloperKey, videoId);
getActivity().startActivity(intent);

Strangely, THAT destroys and recreates my RootActivity as well. My activity doesn't get destroyed and recreated if I launch an intent to open a web URL, why is it getting destroyed and recreated when I launch the YouTubeStandalonePlayer intent?

like image 534
Kenny Wyland Avatar asked Mar 30 '13 02:03

Kenny Wyland


1 Answers

Add to activity that contains YouTubePlayerSupportFragment this attribute

android:configChanges="screenSize|orientation|keyboardHidden"
like image 63
Denys Vasylenko Avatar answered Oct 17 '22 20:10

Denys Vasylenko