我的应用经常出现这个问题:
android.os.TransactionTooLargeException
at android.os.BinderProxy.transact(Native Method)
at android.view.IWindowSession$Stub$Proxy.addToDisplay(IWindowSession.java:683)
at android.view.ViewRootImpl.setView(ViewRootImpl.java:502)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:263)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:286)
at android.app.DialogFragment.onStart(DialogFragment.java:490)
at com.guangzhou.haochuan.tvproject.view.fragment.VideoEndDialog.onStart(VideoEndDialog.java:93)
at android.app.Fragment.performStart(Fragment.java:1724)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:918)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
at android.app.BackStackRecord.run(BackStackRecord.java:684)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:443)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:816)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
at dalvik.system.NativeStart.main(Native Method)
我检查了一些说明交易数据不能太大(> 1MB),但我不知道大数据是怎么来的;我只是在创建它时将Integer Param交易到DialogFragment:
public static VideoEndDialog getInstance(int currentPos,int maxPos){
VideoEndDialog videoEndDialog = new VideoEndDialog();
Bundle bundle = new Bundle();
bundle.putInt(PARAM1,currentPos);
bundle.putInt(PARAM2,maxPos);
videoEndDialog.setArguments(bundle);
return videoEndDialog;
}
我认为它不是太大,谁知道其他原因?谢谢!
答案 0 :(得分:0)
我的DialogFragment整个代码:
public class VideoEndDialog extends DialogFragment{
private static String PARAM1 = "currentPos";
private static String PARAM2 = "maxPos";
private int currentPos = 0;
private int maxPos = 0;
private OnClickListener mListener;
private long mLastClickTime = 0;
FrameLayout lastEpisode;
FrameLayout nextEpisode;
FrameLayout continueWatch;
FrameLayout exit;
TextView lastEpisodeText;
TextView nextEpisodeText;
public static VideoEndDialog getInstance(int currentPos,int maxPos){
VideoEndDialog videoEndDialog = new VideoEndDialog();
Bundle bundle = new Bundle();
bundle.putInt(PARAM1,currentPos);
bundle.putInt(PARAM2,maxPos);
videoEndDialog.setArguments(bundle);
return videoEndDialog;
}
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.setCancelable(false);
currentPos = getArguments().getInt(PARAM1);
maxPos = getArguments().getInt(PARAM2);
//Toast.makeText(getActivity(),"currentPos:" + currentPos + "; maxPos:" + maxPos,Toast.LENGTH_LONG).show();
}
@Override
public void onAttach(Activity activity){
super.onAttach(activity);
if(activity instanceof OnClickListener){
mListener = (OnClickListener)activity;
}else{
throw new RuntimeException(activity.toString()
+ " must implement VideoEndDialog.OnClickListener");
}
}
@Override
public void onStart(){
super.onStart();
mLastClickTime = getCurrentTime();
//Toast.makeText(getActivity(),"mLastClickTime:" + mLastClickTime,Toast.LENGTH_LONG ).show();
}
private int getCurrentTime(){
int currentTime = 0;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HHmmss");
currentTime = Integer.parseInt(simpleDateFormat.format(new Date()));
return currentTime;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
Dialog dialog = getDialog();
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
switch (keyCode){
case KeyEvent.KEYCODE_BACK:
if (getCurrentTime() - mLastClickTime < 2) {
return false;
}else{
VideoEndDialog.this.dismiss();
return true;
}
}
return false;
}
});
View view = inflater.inflate(R.layout.video_end_dialog, container);
lastEpisode = (FrameLayout)view.findViewById(R.id.last_episode);
nextEpisode = (FrameLayout)view.findViewById(R.id.next_episode);
continueWatch = (FrameLayout)view.findViewById(R.id.continue_watch);
exit = (FrameLayout)view.findViewById(R.id.exit);
lastEpisodeText = (TextView)view.findViewById(R.id.last_episode_text);
nextEpisodeText = (TextView)view.findViewById(R.id.next_episode_text);
setViewData();
continueWatch.requestFocus();
return view;
}
@Override
public void show(FragmentManager manager, String tag) {
try {
//在每个add事务前增加一个remove事务,防止连续的add
manager.beginTransaction().remove(this).commitAllowingStateLoss();
super.show(manager, tag);
} catch (Exception e) {
//同一实例使用不同的tag会异常,这里捕获一下
e.printStackTrace();
}
}
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
mLastClickTime = 0;
mListener.onDismiss();
}
private void setViewData(){
//是否有上一集
if(currentPos <= 0){
//没有上一集
lastEpisodeText.setTextColor(getResources().getColor(R.color.un_focus));
}
//是否有下一集
if(currentPos >= maxPos - 1){
//没有有下一集
nextEpisodeText.setTextColor(getResources().getColor(R.color.un_focus));
}
//设置点击
lastEpisode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(currentPos <= 0){
Toast.makeText(getActivity(),"亲,没有上一集",Toast.LENGTH_SHORT).show();
}else{
-- currentPos ;
mListener.onPlay(currentPos);
//Toast.makeText(getActivity(),"currentPos:" + currentPos + "; maxPos:" + maxPos,Toast.LENGTH_LONG).show();
VideoEndDialog.this.dismiss();
}
}
});
nextEpisode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(currentPos >= maxPos -1){
Toast.makeText(getActivity(),"亲,没有下一集",Toast.LENGTH_SHORT).show();
}else{
++currentPos;
mListener.onPlay(currentPos);
//Toast.makeText(getActivity(),"currentPos:" + currentPos + "; maxPos:" + maxPos,Toast.LENGTH_LONG).show();
VideoEndDialog.this.dismiss();
}
}
});
continueWatch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.onPlayCurrent();
VideoEndDialog.this.dismiss();
}
});
exit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.onExit();
VideoEndDialog.this.dismiss();
}
});
}
public interface OnClickListener{
public void onPlay(int playPos);
public void onPlayCurrent();
public void onExit();
public void onDismiss();
}
}