Youtube player support fragment no longer working on Android studio 3.2 (androidx)

前端 未结 6 996
梦谈多话
梦谈多话 2020-11-30 12:35

I just updated my Android Studio to version 3.2 and followed instructions to use androidx.

I\'ve been using a Youtube fragment inside a Fragment activity and everyth

6条回答
  •  孤城傲影
    2020-11-30 12:50

    I got it working by following code chunk.

    Object obj = 
    getSupportFragmentManager().findFragmentById(R.id.youtube_player_fragment);
        if (obj instanceof YouTubePlayerSupportFragment)
            youTubePlayerFragment = (YouTubePlayerSupportFragment) obj;
    

    During debugging I found that the fragmentmanager was coming to be instance of YouTubePlayerSupportFragment only. But compiler was not able to cast it when I would write

    (YouTubePlayerSupportFragment) 
    getSupportFragmentManager().findFragmentById(R.id.youtube_player_fragment);
    

    The above code chunk (instanceof ) worked fine.

提交回复
热议问题