package com.yuqirong.aidldemo;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.annotation.Nullable;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Anyway on 2016/4/19.
 */
public class MyService extends Service {

    private static final String TAG = "MyService";

    private List<Person> persons = new ArrayList<>();

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        Log.i(TAG, "bind success");
        return mBinder;
    }

    private IBinder mBinder = new IMyAidlInterface.Stub() {

        @Override
        public List<Person> addPerson(Person person) throws RemoteException {
            // 需要同步
            synchronized (persons){
                persons.add(person);
                return persons;
            }
        }
    };

}


