2011-09-16 114 views
-3

提供持久存储的样本代码,我在哪里可以找到保存的数据,以及如何显示从持久性存储多个记录在日BB黑莓永久存储

+0

后续的联系可以帮助你。 http://stackoverflow.com/questions/3805182/how-do-i-use-the-persistent-object-store-in-blackberry http://stackoverflow.com/questions/4611817 /持久店 – koti

回答

2

在这里找到下面的代码保存到持久性存储和获取把数据传回:

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

此链接可以帮助你 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(); 

    } 
}