YouTubePlayerSupportFragment开始重复活动 [英] YouTubePlayerSupportFragment starts duplicate Activity

查看:441
本文介绍了YouTubePlayerSupportFragment开始重复活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是YouTubePlayerSupportFragment嵌入YouTube视频在我的应用程序。当嵌入它工作得很好,视频播放,一切都很好。

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.

当我点击全屏按钮我的嵌入的YouTube视频片段,第一次奇怪的事情发生了:它实例现有的封闭活动的新副本......我不知道为什么

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.

我有一个活动,RootActivity,这在ViewPager显示几个片段。我正与目前处理的片段被称为EasyModePurchaseFragment。这EMPF有YouTubePlayerSupportFragment嵌入在其布局的xml:

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"
/>

当我轻触YouTubePlayerSupportFragment的全屏按钮,一个全新的RootActivity被实例化。这是为什么?

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.

编辑:

我也试着拦截onFullScreen()事件,而不是调整的看法,我只是尝试推出一个独立的YouTube播放器,其提供的意向:

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);

奇怪的是,这会破坏并重新创建我RootActivity为好。我的活动不被摧毁并重建,如果我发起的意图,打开一个网页的URL,为什么会被破坏掉,并重新当我启动YouTubeStandalonePlayer意图是什么?

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?

推荐答案

添加到活动包含YouTubePlayerSupportFragment这个属性。

Add to activity that contains YouTubePlayerSupportFragment this attribute

android:configChanges="screenSize|orientation|keyboardHidden"

这篇关于YouTubePlayerSupportFragment开始重复活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆