Android 13下Intent传递IntegerArrayList返回null问题及解决
Android 13下Intent传递IntegerArrayList返回null的问题与解决
自Android 13起,通过Intent传递数据需配置Intent Filter和Categories。我尝试使用Intent.PutIntegerArrayListExtra方法传递数据,配置了如下Intent Filter,但未生效,推测需要指定DataMimeType,但不清楚ArrayList对应的类型。
[IntentFilter(new[] { Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }) ]
更新:问题详情
第一个Activity代码:
var intent = new Intent(this, typeof(ExampleActivity)); intent.PutIntegerArrayListExtra("Items", items.Select(x => (Java.Lang.Integer)x).ToList());
第二个Activity代码:
var items= Intent.GetStringArrayListExtra("Items");
在Android 13上,上述代码获取到的items为null。
解决方案
第一个Activity修改后的代码:
Bundle bundle = new Bundle(); var intent = new Intent(this, typeof(ExampleActivity)); List<Java.Lang.Integer> itemsArrayList = items.Select(x => (Java.Lang.Integer)x).ToList(); bundle.PutIntegerArrayList("Items", itemsArrayList); intent.PutExtras(bundle);
第二个Activity修改后的代码:
Bundle bundle = Intent.Extras; var items = bundle.GetIntegerArrayList("Items");
内容的提问来源于stack exchange,提问作者Ahmet Onay
相关产品推荐
相关产品推荐

