Record Management System的職責(zé)是存儲和唯一標(biāo)識記錄,而表示數(shù)據(jù)的任務(wù)是由應(yīng)用程序來完成的,因此J2ME的開發(fā)人員往往要花費(fèi)更多的精力來處理存儲空間中的數(shù)據(jù)。這樣做的目的是簡化MIDP的實(shí)現(xiàn),使得J2ME的子系統(tǒng)盡量的小巧、靈活。畢竟移動信息設(shè)備的存儲空間和處理器的能力都有限。
Record Store是一系列記錄的有序集合,記錄是不能單獨(dú)存在的,必須屬于Record Store。Record Store保證記錄的讀寫操作都是原子的,數(shù)據(jù)不會被破壞。在API中Record Store是由javax.microedition.rms.RecordStore實(shí)現(xiàn)的,關(guān)于RecordStore的具體操作在接下來的文章中會有詳細(xì)的介紹。
public class CounterCanvas extends Canvas implements CommandListener {
private RMSModel model; private RMSAnalyzer RMSanalyzer; private int interTime; private int counter; private boolean go = true; public static Command backCommand = new Command("退出", Command.EXIT, 3); public static final int INC = 1; public final Timer timer = new Timer();
public CounterCanvas(int interTime, int base, RMSAnalyzer rmsa) throws RecordStoreException { this.interTime = interTime; this.counter = base; this.RMSanalyzer = rmsa; model = new RMSModel(base, RMSanalyzer); this.addCommand(backCommand); this.setCommandListener(this);
TimerTask timerTask = new TimerTask() { public void run() {