寫給初學者Android AIDL必看內容

2021-08-30 19:04:38 字數 1446 閱讀 2033

更好的設計android軟體應該熟悉掌握aidl ipc機制,可以讓你編寫的元件類似windows activex com一樣更好的復用,提供類似像symbian那樣的伺服器機制。服務可以很好的解決在後台執行無ui的視窗。我們建立乙個aidl檔名為 android123.aidl下面是示例**,修改於android sdk文件。

一、建立aidl檔案

package cn.com.android123;

引入宣告 import cn.com.android123.iatmservice;

// 宣告乙個介面,這裡演示的是銀行atm程式

inte***ce ibankaccountservice

二、實現乙個介面

顯示的提供乙個匯出介面,為客戶端提供繫結。

public class remoteservice extends service

if (isecondary.class.getname().equals(intent.getaction()))

return null;

} //第乙個介面

private final iremoteservice.stub mbinder = new iremoteservice.stub()

public void unregistercallback(iremoteservicecallback cb)

};//第二個介面

private final isecondary.stub msecondarybinder = new isecondary.stub()

public void basictypes(int anint, long along, boolean aboolean,

float afloat, double adouble, string astring) };}

三、客戶端互動

通過android.os提供的parcelable型別來傳遞資料,通常我們使用eclipse+adt外掛程式來完成,在eclipse中在 package explorer view檢視上單擊滑鼠右鍵,選擇create aidl preprocess file for parcelable classes(建立aidl預編譯檔案),最終我們建立乙個名為android123.aidl檔案

import android.os.parcel;

import android.os.parcelable;

public final class rect implements parcelable

public rect newarray(int size)

};public rect()

private rect(parcel in)

public void writetoparcel(parcel out)

public void readfromparcel(parcel in)

}

寫給linux Shell程式初學者

在 nix系統啟動最後階段將呼叫乙個非互動的shell程式,然後在shell程式裡啟用圖形客戶端程式,如果選擇不啟用圖形客戶端,則在系統啟動最後階段將呼叫乙個 互動的shell程式。互動shell又包括登陸shell與非登陸shell,登陸shell指的是以bash login 以下所有shell程...

寫給C語言初學者的話

前些天我寫了一篇 unix c語言值得注意的地方 一貼,回貼中談到學習 國外的開源軟體 中的高質量 的問題,但是有朋友跟我說,在看 的過程中感覺難度很大,想想也是如此,動輒十幾萬行的程式如果沒有人指點的話是很難找到切入點的,所以我撰寫了此文希望能對廣大c語言愛好者有所幫助,在文章中有很多煽情的地方還...

寫給測試初學者 問題摘要

1 剛剛接觸軟體測試時間不長,懂得基本的測試原理和測試流程,但是沒有實際的測試經驗。如果我現在想學習測試工具,應該從哪乙個開始學習呢?關於測試工具,現在主流的非主流的,行業的,自動研發的,開源的等等非常多,每個工具都有其優越性和針對性,不然也不會有人去使用。我一直覺得測試注重的還是測試的設計及方法,...