In this article, We are going to see how to store the data in flash memory of the device.

Here, We used the Persistent Store API for store the data in flash memory. The data persists even if you remove the battery from the blackberry device. This is a secure API.

The BlackBerry Persistent Store APIs do not provide a relational database model. You must create an effective object model and manage the relationships between objects, as necessary, using indices and hash tables.It is looks like a key-value model.

Create a Storage – Persistent data Store

1) Import the following class
net.rim.device.api.system.PersistentObject
net.rim.device.api.system.PersistentStore

2) Each persistent object has a unique key for processing, So we need to create a key.
Create a string ( ex: String pObject = “HelloWorldPersistentObject” )
Right click the string and choose the option “convert string to long” (you will get the value like 0Xa1a34567823abc2W )

3) To make the persistent store ,create a one static object for persistentObject

            static PersistentObject persistentObject;

4) To invoke the object using,

           static { persistentObject = PersistentStore.getPersistentObject ( 0Xa1a34567823abc2W); }

Store the Data
To store the new value into the persistent store , invoke the commit().

String[] persondetails = {username , personaldetails, officialdetails }
synchronized(persistentObject) { 
	 persistentObject.setContents(persondetails);
	 persistentObject.commit();
}

Retrieve the Data

synchronized(persistentObject){
	String[] currentPersonInfo = (String [])persistentObject.getContents();
}

Remove the Data

	persistentStore.destroyPersistentObject( 0Xa1a34567823abc2W);

It supports saving to the smartphone’s flash memory, but not to the SD card, it is a good choice for storing data that does not require large amounts of space, such as application settings and user preferences. No size limits for the persistent store and also each object size is 64 KB.

Advertisements