Android运行时:致命异常:主处理数据包裹大小1245464字节错误



恐怕因为图像大小而出现错误,但我没有太多的代码知识。如何修复下面的源代码?

==============================================================================================================================================================================================================================

==

日志猫错误消息:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: im.r_c.android.puz, PID: 18376
java.lang.RuntimeException: 
android.os.TransactionTooLargeException: data parcel size 1245464 
bytes
    at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4006)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6541)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
 Caused by: android.os.TransactionTooLargeException: data parcel size 1245464 bytes
    at android.os.BinderProxy.transactNative(Native Method)
    at android.os.BinderProxy.transact(Binder.java:748)
    at android.app.IActivityManager$Stub$Proxy.activityStopped(IActivityManager.java:4636)
    at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3998)
    at android.os.Handler.handleCallback(Handler.java:789) 
    at android.os.Handler.dispatchMessage(Handler.java:98) 
    at android.os.Looper.loop(Looper.java:164) 
    at android.app.ActivityThread.main(ActivityThread.java:6541) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

====

==================================================================================

这是一个益智游戏App.two活动源代码

游戏活动.java

public class GameActivity extends AppCompatActivity {
   private static final String TAG = "GameActivity";
   public static final int SPAN_COUNT = 3;
   public static final int BLANK_BRICK = 8;
   public static final int[][] GOAL_STATUS = {{0, 1, 2}, {3, 4, 5}, {6, 7, BLANK_BRICK}};
   public static final int MAIL_GAME_STARTED = 100;
   public static final int MAIL_STEP_MOVED = 101;
   public static final int MAIL_GAME_WON = 102;
   public static final int REQUEST_CODE_CHOOSE_PICTURE = 100;
   private Bitmap mFullBitmap;
   private Bitmap[] mBitmapBricks = new Bitmap[SPAN_COUNT * SPAN_COUNT];
   private Timer mTimer;
   private long mStartTime;
   private int mStepCount;
   private TextView mTvTime;
   private TextView mTvStep;
   private Button mBtnChooseAndStart;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
        window.setEnterTransition(new Explode());
        window.setExitTransition(new Explode());
    }


    setContentView(R.layout.activity_game);
    Mailbox.getInstance().atHome(this);
    mTvTime = findViewById(R.id.tv_time);
    mTvStep = findViewById(R.id.tv_step);
    mBtnChooseAndStart = findViewById(R.id.btn_choose_and_start);
}
}

选择活动.java

public class ChooseActivity extends AppCompatActivity {
private static final int CHOOSER_SPAN_COUNT = 2;
private final int[] mResIds = new int[]{
        R.mipmap.pic_1, R.mipmap.pic_2, R.mipmap.pic_3,
        R.mipmap.pic_4, R.mipmap.pic_5, R.mipmap.pic_6,
        R.mipmap.pic_7, R.mipmap.pic_8
};
private Uri[] mUris = new Uri[mResIds.length];

private static String[] PERMISSIONS_STORAGE = {
        Manifest.permission.READ_EXTERNAL_STORAGE,
        Manifest.permission.WRITE_EXTERNAL_STORAGE};
private static int REQUEST_PERMISSION_CODE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_choose);
    for (int i = 0; i < mResIds.length; i++) {
        mUris[i] = ResUtils.getUriOfResource(this, mResIds[i]);
    }
    initView();
}
private void initView() {
    RecyclerView recyclerView = findViewById(R.id.rv_pics);
    assert recyclerView != null;
    CommonRecyclerViewAdapter<Uri> adapter = new CommonRecyclerViewAdapter<Uri>(this, mUris, R.layout.choose_pic_item) {
        @Override
        public void onItemViewAppear(ViewHolder holder, Uri uri, int position) {
            holder.setViewImageResource(R.id.iv_image, mResIds[position]);
        }
    };
    adapter.setOnItemClickListener(new CommonRecyclerViewAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            returnUri(mUris[position]);
        }
    });
    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new GridLayoutManager(this, CHOOSER_SPAN_COUNT));
    recyclerView.addItemDecoration(new SquareGridSpacingItemDecoration(this, R.dimen.brick_divider_width));
}
}

如何修改源代码?

当服务和应用程序之间交换大量数据时,就会发生这种情况(这涉及传输大量缩略图(。实际上数据大小约为 500kb,IPC 事务缓冲区大小设置为 1024KB。我不确定为什么它超过了交易缓冲区。

当您通过 intent extras 传递大量数据时,也会发生这种情况。因此,最终解决此 TransactionTooLarge 异常的是识别具有其从属片段、视图等将数据包添加到捆绑包的活动。然后我在上述活动中运行了这段代码:

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    //Clear the Activity's bundle of the subsidiary fragments' bundles.
    outState.clear();
}

这为我解决了它。希望这对那里的人有所帮助!

最新更新