android aidl 處理序間通訊需要注意的地方(android.os.TransactionTooLargeException)

來源:互聯網
上載者:User

標籤:

轉自: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)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.