標籤:
轉自:http://blog.sina.com.cn/s/blog_4e1e357d0102wau9.html
1.bus工程實現通過service實現aidl實體類
2.actor工程通過發起bindservice,根據action去啟動遠程(跨進程的)bus上的aidl。 那麼問題來了,我們知道,linux系統處理序間通訊,各個進程間資源是隔離的,兩個進程間需要通訊,就要把msg轉換成底層os系統能夠識別的資料單元,在Android裡面的方案是aidl+parcelbal的序列化。 為了類比和測試aidl的效能問題,我做了個簡單實驗,在Android中,處理序間通訊通過binder實現,bind是通訊的資料載體,當序列化後的資料單元過大時,就會出問題,報出android.os.TransactionTooLargeException。 http://developer.android.com/reference/android/os/TransactionTooLargeException.html 官方文檔裡有說明,最大通常限制為1M.也就是說如果大於1M資料的話,就應該分開傳。理論上說,應該都是對象和字串類型的資料為主,只要不是大圖片實體等問題,一般應該夠用。我這邊做了一個測試,序列化傳送了450k的String被序列化 後的資料,耗時使用了33秒的時間。 try {StringBuilder sb = new StringBuilder();for(int i = 0;i< 30;i++){sb.append(new String (stringMsg));}System.out.println( "actor time start :" + System.currentTimeMillis());binder.sendMsg("msg from actor : " + sb.toString());} catch (RemoteException e) {// TODO Auto-generated catch blocke.printStackTrace();}------ public static BusCore coreBinder = new BusCore.Stub() { @Overridepublic void sendMsg(String msg) throws RemoteException {Log.d("", " RemoteBusCoreService msg:" + msg); System.out.println("buscore time end :" + System.currentTimeMillis());}}; 對於遠程服務,必須調用 bindService()方法,而不是 startService()方法。 今天剛好是在做架構性 實現方案測試時,稍微檢測了下個,mark下。
android aidl 處理序間通訊需要注意的地方(android.os.TransactionTooLargeException)