gpt4 book ai didi

java - Android运行时: FATAL EXCEPTION: main Process data parcel size 1245464 bytes error

转载 作者:行者123 更新时间:2023-12-02 04:55:47 24 4
gpt4 key购买 nike

恐怕由于图像大小的原因我会遇到错误,但我没有太多的代码知识。如何修复下面的源代码?

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

Logcat 错误消息:

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 Activity源码

GameActivity.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);
}
}

选择Activity.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 extra 传递大量数据时,也可能会发生这种情况。因此,最终解决此 TransactionTooLarge 异常的方法是识别具有其从属 fragment 、 View 等的 Activity,将数据包添加到 bundle 中。然后我在上述 Activity 中运行了这段代码:

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

这为我解决了这个问题。希望这可以帮助那里的人!

关于java - Android运行时: FATAL EXCEPTION: main Process data parcel size 1245464 bytes error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56411933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com