gpt4 book ai didi

c# - Monodroid 在 Intent 中传递 int[]

转载 作者:行者123 更新时间:2023-11-30 03:43:36 25 4
gpt4 key购买 nike

我有两个 Activity A 和 B。我从 Activity A 开始 Activity B,如下所示:

var intent = new Intent(this, typeof (BActivity));
StartActivityForResult(intent, 1);

如果您在 Activity B 上按下按钮,我必须将一个 int[] 数组传递给 Activity A,我创建了一个执行此操作的测试代码:

var intent = new Intent();
int[] array = {1, 2, 3};
intent.PutExtra("__extra__", array);
SetResult(Result.Ok, intent);
Finish();

但每当我尝试从 Intent 中获取此值时,我都会收到 null。这是我的尝试:

var value = data.GetIntArrayExtra("__extra__");

我在这里做错了什么?我对字符串进行了同样的尝试,并且在我看来它起作用了,只是 int 数组不起作用......

最佳答案

试试看:

Bundle bdl = new Bundle();
int[] array = {1, 2, 3};
bdl.PutIntArray("__extra__",array);

Intent intent = new Intent();
intent.PutExtra("extra", bdl);
SetResult(Result.Ok, intent);
Finish();

OnActivityResult 上:

Bundle credBdl = data.GetBundleExtra("extra");
int[] array=credBdl.GetIntArray("__extra__");

关于c# - Monodroid 在 Intent 中传递 int[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15358702/

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