AIDL中的in out inout

AIDL中的in out inout,官方是這樣介紹的,

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 connot be otherwise .

說的很抽象,我的理解是 如果客戶端調(diào)用服務(wù)端實現(xiàn)的接口,在服務(wù)端修改參數(shù)的屬性的話 對客戶端原來的對象如果同步修改的話 就需要設(shè)置為out/inout,如果修改客戶端的參數(shù)的屬性不影響原來的對象,就用in

interface StudentManager {
    /**
     * Demonstrates some basic types that you can use as parameters
     * and return values in AIDL.
     */
    void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
            double aDouble, String aString);
    void addStudentInout(inout Student s);//
    void addStudentIn(in Student s);
    //void addStudentOut(out Student s);//聲明為out的話 一直報錯 不知道什么原因
    List<Student> getStudents();
    void clear(int isClear);
}
public class StudentService extends Service {
    private List<Student> students = new ArrayList<>();

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return binder;
    }

    /**
     * 實現(xiàn)StudentManager接口
     */
    private StudentManager.Stub binder = new StudentManager.Stub() {
        @Override
        public void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString) throws RemoteException {

        }

        @Override
        public void addStudentInout(Student s) throws RemoteException {
            s.setName("update");//修改name屬性 客戶端s對象的name屬性做響應(yīng)的修改
            students.add(s);
        }

        @Override
        public void addStudentIn(Student s) throws RemoteException {
            s.setName("update");//修改name屬性 不會影響客戶端對象的屬性
            students.add(s);
        }

/*
        @Override
        public void addStudentOut(Student s) throws RemoteException {
            students.add(s);//如果接口中申明為out 參數(shù)的話一直報錯 不能通過編譯,暫時不知道什么原因
        }
*/

        @Override
        public List<Student> getStudents() throws RemoteException {
            return students;
        }

        @Override
        public void clear(int isClear) throws RemoteException {
            students.clear();
        }
    };
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容