ブラックベリーアプリケーションでユーザーが利用できる通知の数を記録する永続的な共有変数を作成しようとしています。この番号はホーム画面に表示され、デバイスの電源を切ってもアプリケーション自体をチェックしてから番号がリセットされるまで保持する必要があります。 http://supportforums.blackberry.com/t5/Java-Development/Storing-persistent-data/ta-p/442747Javaの永続ストアJavaランタイムストア
:
import net.rim.device.api.system.RuntimeStore;
public class IconManager {
private static IconManager _instance;
private static final long GUID = 0xab4dd61c5d004c18L;
private int iconCount;
// constructor
private IconManager() {
iconCount = 0;
}
public static IconManager getInstance() {
if (_instance == null) {
_instance = (IconManager) RuntimeStore.getRuntimeStore().get(GUID);
if (_instance == null) {
IconManager singleton = new IconManager();
RuntimeStore.getRuntimeStore().put(GUID, singleton);
_instance = singleton;
}
}
return _instance;
}
public int getCount() {
return iconCount;
}
public void setCount(int count) {
iconCount = count;
}
}
が、私は主に永続ストアの部分を把握しようとするために、このサイトを使用している:私は、バックグラウンド・プロセスと以下のUIアプリ自体の間で変数を共有するためにシングルトンを使用しています上記のランタイムストアを使用して永続ストアを実装する代替手段はありますか?私はもともとBlackberryの例のコードを使うことを考えていましたが、これをどうやって行うのか混乱しています。別のスレッドのユーザーからmparizeauは、次のように書いた:
persistentCount = PersistentStore.getPersistentObject(0xdec6a67096f833cL);
synchronized (persistentCount) {
if (persistentCount.getContents() == null) {
persistentCount.setContents(new StoreInfo());
persistentCount.commit();
}
}
_data = (StoreInfo)persistentCount.getContents();
あなたはそれを更新し、PersistentStoreに保存したいときに今、あなたのようなもの持つことができます。
_data.incElement();
synchronized(persistentCount) {
persistentCount.setContents(_data);
persistentCount.commit();
}
を、これは上記で使用することができ何とかコード?私は非常にJavaとBBの開発には非常に新しいので、任意の助けをいただければ幸いです。
正確に必要なものは?明確に指定してください。 –