Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified
Accepted Solution

When to use persistent storage?

Hello everyone,

 

I have created applications that use persistent storage, and I have created applications that use an SQLite database.  I have also created applications that use both.  My question is this:

 

Should persistent storage be limited in what it stores?  For example, should persistent storage be used more for purposes of storing simple things such as "the user's selected font size for the application" and "a hashtable of a default language and its language code for the application"?  Or, might it also be recommended to act almost as a database, for example when a user doesn't have an SDCard installed - in which case you would store many vectors of objects and such?

 

Is there a possibility of persistent storage not being available due to limited space?  For example, if the user has a lot of other applications that use up the persistent storage?

 

Finally, I believe that persistent storage is only erased in events of a battery pull, etc.  Is it also possible for it to erase in other ways, like a restart?

 

Thanks!

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: When to use persistent storage?

I would look at the characteristics of the data I am storing and the characteristics of the options (SQLite, file on SD Card or PeristentStore) and make a decision based on that.

 

The key characteristics for me are

a) Size of data

b) Requirement for presence

c) Use of data

d) Removal of data

 

Working through these:

 

a) Size

 

There is a reasonable amount of PeristentStore available, even only older devices.  If you had a Vector of 10,000 Strings, each 100 bytes long, that is still only ! Mb of storage.  And there are low storage managers that you can listen for and tidy up your use of PersistentStore.  But there is more space on an SD Card, and no chance of you screwing the Blackberry is you use up too much memory (if you over use PersistentStore the device will clear out things like old emails which might upset your users). 

 

b) Requirement

 

Remember your users can pull the SD Card, and all the data

 

c) Use of data

 

If the data lends itself to be used an an Object fashion, then it seems appropriate way to store it in that form, which means there is no 'serialization' required to turn it into a flat file or conversion to turn it into a table.  But things like images, sound files and the like gain no advantages being stored as an Object.  So stick them on the SD Card. 

 

d) Removal

 

PersistentStore is removed when the application is removed, which can be a good thing. 

 

In summary, there no right answer here, use the best option for the job you have.

 

Regarding your questions:

 

"Is there a possibility of persistent storage not being available due to limited space?"

Yesish, as mentioned, there is the low storage manager.  But to be honest, you could store megabytes of data in a table like structure in PersistentStore, and as long as you are careful, this will work fine. 

 

"I believe that persistent storage is only erased in events of a battery pull"

No, it stays over a battery pull.  To erase, the usual ways are to wipe the device, or remove the application that uses it. 

 

 

Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: When to use persistent storage?

Hi peter_strange,

 

I thank you for the very thorough answer.  I found your section on "Size" particularly helpful.  There are certainly a lot of factors to take into consideration with storage, and that is apparent from your response.  After digesting this information during my daily run, I've decided to use a database when the SDCard is present, and PersistentStorage when it is not.  I'm not going to use PersistentStorage heavily to store relational data, however, instead I am going to store some basic information and do more requests to my webservice to retrieve the detailed data.

 

Your help is always appreciated.

 

Kevin

Highlighted
Contributor
Posts: 11
Registered: ‎06-21-2011
My Device: Bold
My Carrier: Smart

Re: When to use persistent storage?

Hi Peter,

How can i view the persistent storage file in my blackberry phone?
Is there a reason for sudden deletion of Persistent storage?


Thanks