开发者

Blackberry Persistent Storage [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its c开发者_StackOverflow中文版urrent form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

provide a sample code for persistent storage and where can i find the saved data and how to show multiple records from persistent storage to on th BB


Find here the code below to save to persistent store and get the data back:

    protected static long infoKey = 0x26a46589530f909aL;
    public static Vector getInfo() {
        PersistentObject object =  PersistentStore.getPersistentObject( infoKey );
        myVector table = (myVector) object.getContents();
        return table;
    }

    public static void setInfo(Vector obj) {
        try { PersistentStore.destroyPersistentObject(infoKey); } catch (Exception ex) { }
        PersistentObject object = PersistentStore.getPersistentObject( infoKey );
        object.setContents(obj);
        object.commit();
    }


This link may help you Using Persistent Store in BlackBerry

public DataContext() {    

    // Hash of examples.persistentstore.
    persistentObject = PersistentStore.getPersistentObject(0xc8027082ac5f496cL);

    synchronized(persistentObject) {

        settingsTable = (Hashtable)persistentObject.getContents();
        if (null == settingsTable) {
            settingsTable = new Hashtable();
            persistentObject.setContents(settingsTable);
            persistentObject.commit();
        }
    }

}
class HomeScreen extends MainScreen {

    private EditField homepageEditField;

    private MenuItem saveMenu = new MenuItem("Save", 100, 100) {
        public void run() {

            Screen screen = UiApplication.getUiApplication().getActiveScreen();
            try {
                screen.save();
            } catch (java.io.IOException ex) {
                Dialog.inform("Could not save settings.");
            }
            screen.close(); 

        }
    };

    public HomeScreen() {

        super();

        this.setTitle("Persistent Store Example");

        DataContext dataContext = new DataContext();        

        homepageEditField = new EditField("Home page: ",(String)dataContext.get("HomePage"),256,EditField.FIELD_RIGHT);
        this.add(homepageEditField);

    }

    protected void makeMenu(Menu menu, int instance) {

        super.makeMenu(menu, instance);

        menu.add(saveMenu);
    }

    public void save() throws java.io.IOException {

        DataContext dataContext = new DataContext();

        dataContext.set("HomePage",homepageEditField.getText().trim());
        dataContext.commit();

    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜