??????????????е????????????????????????????????????????????????????????????????????????????????????????????????????????????????Э??????????????
????????????????о????????????????????Ч???????????????????????????????????????????????????????????????????Χ??????????????????????????????????????????(????????)??????????????????????????(?????????(????)????????????μ???????????????????)??
?????????ν??
???????????????????????????????????????????????????????á?
????1??????
????Android?????????????б????????SharedPreference????????????
????????????????????????????д???????????????????????????????????
??????????????????μ???????д?????????(???????????)???????????д????IO?????
???????????????????????????????SharedPreference???п????????д?????????????????????Android???????ContentProvider?????????????Щ??????
???????????????????????????Щ???飬????????洢???(???????)????????????????(SharedPreference)????????????????????????(?????)?????????????
????????????ContentProvider????????????????????鷳?????????????????????
????2??IPC(????????)
????IPC??????????????????????????????????????RPC(?????????)??Android???????????????AIDL??????
??????????????????????????????
????1??????AIDL???
????2?????AIDL?????????
????3????????Service?????????????????AIDL???Binder????(?????÷?)
????4????Service?????Binder???????Binder??????з???????(???÷?)
???????????????????????????????????д????????
????????????????·??
????1??????????????????????(?????????????????????AIDL?????????????)
????2???????????????????ж??????????л??????????????????????????????????????????????????ν??????á?
???????????·??????????????
????1???????????????????AIDL?????
????2?????AIDL?????????(???????????)
????3?????????(if (??????????) { ????????????; } else { ???????????; })
????4??????????????????????????????????
????(????????????????????????????)
????3????(??)
?????????????????????
?????????????????????????????????裺
????· ????AIDL???
????· ???AIDL?????????
????· ??????Service?????????????????AIDL???Binder????(?????÷?)
????· ??Service?????Binder???????Binder??????з???????(???÷?)
????1?????????
?????????
??????????????????AIDL??????????????????????AIDL?????????????????
????· ?????????????????????????????????????????????????????
????· ????????????????????????????????(Binder)???????????????е?????Binder(RPC???Proxy)????????????????????????????????????????????ó???????????????????
??????????????????????????????80%????????????????
????2?????????????
??????μ?20%?????????????
????· ????AIDL???????????????????AIDL???
????· ??????????????????????????????????????????????????????ɡ?
??????????????????????????????????????????????????????????
????· ???Service?????????????AIDL?????
????· onServiceConnected??????????????????????????????????
??????????????????е??????????????????????????????????????????????
????д??AIDL????????????????????Parcelable??Parcelable??????????????????????????л???????л??????????????????????????????????Parcel????????????????????writeStrongInterface??readStrongBinder?????????????????Binder????????л???????л???????
????????????????????????е???????writeStrongInterface???л????????????????????????????????readStrongBinder????????????????????????????????
??????????????????????????????????
????3??Word is cheap?? show me the code
????GayHub??????????????????Sample
????3.1??????
???????????????????????????????
????· ???????????AIDL?????????????
????· Parcelable???????л?(Stub)??????л?(Proxy)????????
????3.2?????-????
?????????????????????????
????SingletonA??A???????A?????
????SingletonA.aidl??????AIDL????
????SingletonAImp.java???????????????
????SingletonB??B???????B?????
????SingletonB.aidl??????AIDL????
????SingletonBImp.java???????????????
????SingletonC??C???????C?????
????SingletonC.aidl??????AIDL????
????SingletonCImp.java???????????????
??????????????????????????????getInstance?????????£????????????????????ж??????????????
public static synchronized SingletonA getInstance() {
if (ProcessUtils.isProcessA()) {
if (INSTANCE == null) {
INSTANCE = new SingletonAImp();
}
return INSTANCE;
} else {
if (INSTANCE == null) {
/** ??????? */
Intent intent = new Intent(
App.getContext()?? ServiceA.class);
App.getContext().bindService(intent??
new InstanceReceiver()??
Context.BIND_AUTO_CREATE);
}
return INSTANCE;
}
}
???????getInstance??????????????????????????????
??????????????????????????????
????ServiceA.class
????InstanceReceiver