您的位置:首页 > 大数据 > 人工智能

关于AIDL中Map参数传递的问题

2017-12-11 10:39 961 查看
我们都知道aidl是支持map作为参数传递的,但前提是map不能是泛型并且数据类型必须是aidl所支持的String,int等。Map

interface IMyAidl {
void test(Map<String,String> datas);

}


报错如下:

aidl.exe E 12-11 10:26:04  4948  5096 type_java.cpp:902] Don't know how to create a Map<K,V> container.
aidl.exe E 12-11 10:26:04  4948  5096 type_namespace.cpp:129] In file E:\ASProject\UI1.1\app\src\main\aidl\com\hencoder\hencoderpracticedraw1\IMyAidl.aidl line 7 parameter datas (argument 1):
aidl.exe E 12-11 10:26:04  4948  5096 type_namespace.cpp:129]     unknown type

上述错误中首先说明不知道如何创建Map<K,V>container,但是aidl肯定是支持map参数传递的。最后还指出,这是一个不知道的类型。


我在网上查了一些资料,发现很少介绍这一方面的。最后在不断的尝试中发现如下写法能解决:

interface IMyAidl {
void test(in Map datas);

}


这里需要注意

'Map' can be an out type, so you must declare it as in, out or inout.


所以在使用的时候map必须声明为in、out或者inout。接下来就能直接使用了。

因为网上对于此问题记录太少,所以我写出来解答与我一样遇到此问题的人。

备注:至于为什么这样使用,目前还不太清楚,请多指教。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: