2011-01-06 55 views
0

我正在開發BlackBerry應用程序。我想在手機中存儲多個用戶的詳細信息。我必須爲每個用戶存儲用戶名,名字,姓氏,電子郵件ID,電話號碼等數據。任何人都可以爲我提供一個持久存儲的示例代碼,我可以將所有這些數據存儲在一個向量中,然後再檢索。在BlackBerry中使用Persistent Store

回答

3

此鏈接應回答大部分您需要知道的內容 - http://www.miamicoder.com/post/2010/04/13/How-to-Save-BlackBerry-Application-Settings-in-the-Persistent-Store.aspx

下面是我的一個項目的一些代碼。

public class PreferencesStore 
{ 
    // Not a real key, replace it with your own.  
    private static long m_lTabulaRectaKey = 0l; 

    public static Vector getTabulaRectas() 
    { 
     Vector vecTabulaRectas = new Vector(); 

     PersistentObject poObject = PersistentStore.getPersistentObject(m_lTabulaRectaKey); 

     if(poObject.getContents() != null) 
     { 
      vecTabulaRectas = (Vector)poObject.getContents(); 
     } 

     return vecTabulaRectas; 

    } 

    public static void addTabulaRecta(TabulaRecta a_oTabulaRecta) 
    { 
     Vector vecTabulaRectas = getTabulaRectas(); 

     vecTabulaRectas.addElement(a_oTabulaRecta); 

     PersistentObject poObject = PersistentStore.getPersistentObject(m_lTabulaRectaKey); 

     poObject.setContents(vecTabulaRectas); 

     poObject.commit(); 
    } 
} 
+0

非常感謝你的幫助zechariahs.I感謝你親愛的:) – user469999 2011-01-06 08:07:47