40

I'm programming a radio streaming app. I run the "radio playing" as a remote Service by using AIDL interface technique to communicate with the Service. But I don't really understand one thing.

What is the "out" in a AIDL interface parameter value?

Like this:

String doSomething(in String a, out String[] b);

I understand "in", that is sending data to the remote when the method is called from activity.

What is the "out", and why we need "in" and "out" in same method? In which case are they("out/inout") used? Why is the String[] "out"?

Please help..

1
  • 3
    I think that @gladed answered to your question exhaustively. It would be nice if you check his answer. Jan 13, 2012 at 17:22

2 Answers 2

55

In AIDL, the out tag specifies an output-only parameter. In other words, it's a parameter that contains no interesting data on input, but will be filled with data during the method.

For example, a method that copies an array of bytes might be specified like this:

void copyArray(in byte[] source, out byte[] dest);

The inout tag indicates that the parameter has meaning on both input and output. For example:

void charsToUpper(inout char[] chars);

This is important because the contents of every parameter must be marshalled (serialized, transmitted, received, and deserialized). The in/out tags allow the Binder to skip the marshalling step for better performance.

2
  • Do you mean that the dest object is an "empty array" or "null" when calling the method? Dec 31, 2020 at 6:51
  • An "out" parameter should receive a non-null object with undefined contents.
    – gladed
    Dec 31, 2020 at 22:34
14

Here it goes,

  • Its only a directional tag indicating which way the data goes.
    • in - object is transferred from client to service only used for inputs
    • out - object is transferred from client to service only used for outputs.
    • inout - object is transferred from client to service used for both inputs and outputs.
  • All non-primitive parameters require a directional tag indicating which way the data goes. Either in, out, or inout.

  • Primitives are in by default, and cannot be otherwise

  • Please note, RPC calls from clients are synchronous.
  • You should limit the direction to what is truly needed, because marshaling parameters is expensive.

Example: Please check the below AIDL interface to understand it in a better way.

package com.hardian.sample.aidl;
import com.hardian.sample.aidl.TeamMember;

interface ITeamManageService {
void getTeamCaptian(out TeamMember member);
void updateTeamMember(inout TeamMember member, in boolean isLeader);
oneway void removeTeamMember(in TeamMember member);
}

Here we have used out, in, inout directional tags to indicate which way the data goes.

  1. getTeamCaptian(out TeamMember member) : Get the captain of the team. Here the "out" directional tag means, when the client calls this method, the "member" object has no relevant data, but the server shall make changes to the "member" object, so the client shall get the updated "member" object. In fact, the method call is synchronous.

  2. updateTeamMember(inout TeamMember member, in boolean isLeader) : Update the captian of the team. Here the "inout" directional tag means, when the client calls this method,the "member" object has relevant data in it. And the server shall use the input data and process it. Once the process completed, the client shall get the relevant data back. In fact, the method call is synchronous.

  3. removeTeamMember(in TeamMember member) Remove a member from the team. Here the "in" directional tag means, the "member" object is transferred from client to service only used for inputs. If any changes are made to the "member" object in the service then it won’t reflect in the client. The method call is asynchronous, we can put the "oneway" keyword to the method signature. Asynchronous methods must not have "out" and "inout" arguments, they must also return void.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.