将参数传递给AIDL

时间:2012-06-26 15:20:17

标签: java android function aidl

我的AIDL文件中有一个功能

int getAvailableTokens(out List<String> list);

从主类我想调用这个函数并给出参数List<String> mylist,顺序函数将设置它。我怎么能这样做?

EDITED

int getAvailableTokens (List<FidoTokenInfo> list) throws RemoteException {
    // EDITED: The list must be set in this way!!!
    list.addAll(mFidoDsm.getList());
    // THIS WAY IS NOT CORRECT !!!
    // list = mFidoDsm.getList();
    Log.i(TAG, "list .size() = " + list.size()); // here list size is 1.
}


// First this function calles.
public List<FidoTokenInfo> getAllTokens () throws FidoException {
    List<String> tokenList = new ArrayList<String>();;

    try {
       int error = dsmService().getAvailableTokens(tokenList);
       Log.i(TAG, "tokenList.size() = " + tokenList.size()); // here list size is 0.
       return tokenList;
    } catch (RemoteException e) {
    }
}

Okey我做了一些更改,这是我的代码,因为你可以看到我从getAvailableTokens函数调用getAllTokens函数并作为参数传递给getAvailableTokens list {{1}然后在tokenList我设置了那个列表,然后我检查它的大小是1,但是当我检查列表getAvailableTokens的大小时它是0但是为什么?

1 个答案:

答案 0 :(得分:1)

在.aidl文件中,您应添加inout而不是out。在这种情况下,您应该在主类中初始化列表:

List<String> myList = new ArrayList<String>();
int error = getAvailableTokens(mylist);
int size = myList.size();