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
PaoloLim
Posts: 21
Registered: ‎07-16-2008
My Device: Not Specified
Accepted Solution

Saving an object in your application?

Hello,

I am developing on JDE 4.1 on a 7290 with OS version 4.1. I have a string I want to save from one of my forms, so I create an instance of Persistent object then place it into the Persistent store.

It works fine while I am running my application. My problem is that when I exit the application, it seems to get removed and the string is null again. I use a constant ID that was generated from the hash of the packagename.variablename.

What I want is for the string to be saved even through power offs. I am wondering if I am approaching it the right way, or if I am doing it wrong. If I'm doing it wrong, what do I need to do to correct it?
Retired
bzubert
Posts: 86
Registered: ‎07-11-2008
My Device: Not Specified

Re: Saving an object in your application?

Using the PersistentStore will meet your requirements here.  Please take a look at the memorydemo that ships with the JDE for best practices when using these classes.

 

The sample app can be found here:

 

C:\Program Files\Research In Motion\BlackBerry JDE 4.2.1\samples\com\rim\samples\device\memorydemo

Brian Zubert
Technical Partnership Manager
Research In Motion
Developer
PaoloLim
Posts: 21
Registered: ‎07-16-2008
My Device: Not Specified

Re: Saving an object in your application?

Yes, I that was what I was using.  I found that whenever I exitted the application, my clean up method gets called and I call the destroyPersistentObject method in it.  I removed the line and it appears to be working fine now. 

 

Question though, I want that object to be there for as long as the application is installed, but what will happen to the object if/when my app is removed?  How will it be cleaned up/removed? Will it be cleaned up implicitly or will I need to explicitly destroy it before uninstall?  If it's the latter, how would I go about doing it? 

Retired
mkirkup
Posts: 179
Registered: ‎07-14-2008
My Device: Not Specified

Re: Saving an object in your application?

To ensure that your PersistentStore object is removed when your application is removed you need to make sure that root object of your PersistentStore (the object passed into your call to setContent()) is defined within the package of your application.  

 

For example, instead of using a Hashtable as the root object you can use MyHashtable which is a class defined in your package that simply extends Hashtable.  This tells the VM that no one else on the device will use this class once your application is removed so it will delete your PersistentStore object.

 

If you would like your data to remain on the device after your application is removed then you would want to leverage a system class (like Hashtable) since it could be used across any other application.

 

 

Mike Kirkup
Director, Developer Relations
Developer
jhfisher
Posts: 16
Registered: ‎07-14-2008
My Device: 8310

Re: Saving an object in your application?

aah, thanks for that mike, you explained it clearly, it's something i've never understood until now (i better go and refactor some datastore classes...)
Developer
PaoloLim
Posts: 21
Registered: ‎07-16-2008
My Device: Not Specified

Re: Saving an object in your application?

Ok thank you very much guys.  I think I have it figured out now.
Developer
sankarcj
Posts: 57
Registered: ‎09-12-2008
My Device: Not Specified

Re: Saving an object in your application?

what are the variables we can store in a single persistent object?

 

i know we can store String. is it possible to store Date and other fields in the same persistent object?

 

currently i'm converting all my datas to string and storing it in the persistent object. is it possible to store int as int and date as date?...

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Saving an object in your application?

[ Edited ]
Have a look at the JavaDocs for the Persistable interface.  All classes that have implemented it can be stored within a persistent object.
Message Edited by MSohm on 10-06-2008 10:06 AM
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
richard_puckett
Posts: 191
Registered: ‎04-03-2008
My Device: Bold 9700

Re: Saving an object in your application?

lol.  I think Mark means "Persistable" not "Perishable"  :smileyhappy:
BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Saving an object in your application?

That's right, posted fixed.  :smileyhappy:
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker