-4

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

mehar
  • 7
  • 1
  • Follow links may help you. http://stackoverflow.com/questions/3805182/how-do-i-use-the-persistent-object-store-in-blackberry http://stackoverflow.com/questions/4611817/persistent-store – koti Sep 16 '11 at 08:09

2 Answers2

2

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();
    }
Farid Farhat
  • 2,300
  • 1
  • 16
  • 29
1

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();

    }
}
Community
  • 1
  • 1
koti
  • 3,681
  • 5
  • 34
  • 58