致命异常:java.lang.IllegalStateException:android.os.TransactionTooLargeException

时间:2015-12-01 13:44:47

标签: android android-fragments android-youtube-api

我在片段

中的certian时间收到此错误
Fatal Exception: java.lang.IllegalStateException: android.os.TransactionTooLargeException
       at com.google.android.youtube.api.jar.client.RemoteEmbeddedPlayer.x(SourceFile:532)
       at com.google.android.apps.youtube.api.jar.a.a.w(SourceFile:472)
       at com.google.android.youtube.player.internal.h.onTransact(SourceFile:390)
       at android.os.Binder.transact(Binder.java:361)
       at com.google.android.youtube.player.internal.d$a$a.r(Unknown Source)
       at com.google.android.youtube.player.internal.s.h(Unknown Source)
       at com.google.android.youtube.player.YouTubePlayerView.e(Unknown Source)
       at com.google.android.youtube.player.YouTubePlayerSupportFragment.onSaveInstanceState(Unknown Source)
       at com.redeagle07.alahly.youtube.YouTubeFragment.onSaveInstanceState(YouTubeFragment.java:161)

这是引发错误的行

    @Override
public void onSaveInstanceState(Bundle bundle) {
    super.onSaveInstanceState(bundle);
    bundle.putString(KEY_VIDEO_ID, mVideoId);
}

这就是我从MainActivity添加片段的方式

final YouTubeFragment fragment = YouTubeFragment.newInstance(list.get(position).getID());
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slideup, R.anim.slideout, R.anim.slideup, R.anim.slideout);
ft.addToBackStack("xyz");
ft.add(android.R.id.content, fragment).commitAllowingStateLoss();

EDIT1:

整个YoutubeFragment类

公共类YouTubeFragment扩展BackYoutubeFragment实现了YouTubePlayer.OnInitializedListener {

private static final int RECOVERY_DIALOG_REQUEST = 1;

private static final String KEY_VIDEO_ID = "KEY_VIDEO_ID";

private String mVideoId;

private ShowingAd mListener;

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    try {
        mListener = (ShowingAd) context;
    } catch (ClassCastException e) {
        throw new ClassCastException(context.toString() + " must implement DrawerLockout");
    }
}

@Override
public void onDetach() {
    super.onDetach();
    mListener = null;
}



/**
 * Returns a new instance of this Fragment
 *
 * @param videoId The ID of the video to play
 */
public static YouTubeFragment newInstance(final String videoId) {
    final YouTubeFragment youTubeFragment = new YouTubeFragment();
    final Bundle bundle = new Bundle();
    bundle.putString(KEY_VIDEO_ID, videoId);
    youTubeFragment.setArguments(bundle);
    return youTubeFragment;
}


@Override
public String getTagText() {
    return null;
}

@Override
public boolean onBackPressed() {
    try {
        getFragmentManager().popBackStack();
        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    }catch (NullPointerException e){
        return true;
    }
    return false;
}

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    final Bundle arguments = getArguments();

    if (bundle != null && bundle.containsKey(KEY_VIDEO_ID)) {
        mVideoId = bundle.getString(KEY_VIDEO_ID);
    } else if (arguments != null && arguments.containsKey(KEY_VIDEO_ID)) {
        mVideoId = arguments.getString(KEY_VIDEO_ID);
    }

    initialize("xxxx", this);
}

/**
 * Set the video id and initialize the player
 * This can be used when including the Fragment in an XML layout
 * @param videoId The ID of the video to play
 */
public void setVideoId(final String videoId) {
    mVideoId = videoId;
    initialize("xxxx", this);
}

@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean restored) {
   try {
       mListener.showingAds(0);
       if (mVideoId != null) {
           youTubePlayer.setShowFullscreenButton(false);
           if (restored) {
               youTubePlayer.play();
               youTubePlayer.setFullscreen(true);
           } else {
               youTubePlayer.loadVideo(mVideoId);
               youTubePlayer.setFullscreen(true);
           }
       }
   }catch (NullPointerException| IllegalStateException e){
       e.printStackTrace();
   }
}


@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
    if (youTubeInitializationResult.isUserRecoverableError()) {
        youTubeInitializationResult.getErrorDialog(getActivity(), RECOVERY_DIALOG_REQUEST).show();
    } else {
        //Handle the failure
        Toast.makeText(getActivity(), "FAIL", Toast.LENGTH_LONG).show();
    }
}

@Override
public void onSaveInstanceState(Bundle bundle) {
    super.onSaveInstanceState(bundle);
    bundle.putString(KEY_VIDEO_ID, mVideoId);
}

}

0 个答案:

没有答案