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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile
Accepted Solution

Persitible Structure Change

Hello all,

 

I am planning on upgrading an application but it seems I forgot about the possibility of the structure of my class changing in the future by adding other objects to it.

 

Is the best practice to just have place holders in a class?

 

e.g.

 

public class Settings implements Persistable{

int placeholder1;

int placeholder2;

int placeholder3;

...

}

 

How should I handle the change to the format in an upgrade, create a mirror of my old class, read it in the updated app, then save it in the new structure and save that?

Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Persitible Structure Change

you could use a mutable object, like hashtable, for your settings.
this allows you to add and remove settings without the resulting config object being incompatible.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile

Re: Persitible Structure Change

Is this common practice when making apps that need to save settings?
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Persistable Structure Change

[ Edited ]

It is certainly the way I recommend.  I particularly like Hashtable. 

Developer
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile

Re: Persitible Structure Change

Thanks, I will have a look at it.
Contributor
Posts: 12
Registered: ‎06-16-2011
My Device: 9000
My Carrier: Vodafone

Re: Persitible Structure Change

Yes... One good thing that you can do...

 

Use IntHashtable Instead of Hashtable and define all int keys whatever you want to put on that and put the value on IntHashTable.

Highlighted
Developer
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile

Re: Persitible Structure Change

Well actually I have a custom class that I am saving which contains other classes. So Im not so sure that IntHashTable would work if its dedicated to only integer objects.

So hopefully that one is compatible with HashTable, and when I modify the items inside of this custom class I guess I can read it and then update it to the new format.

One thing I do not understand is how it will work if a user decides not to take one upgrade and then go directly from 1.0 -> 1.2 bypassing 1.1?

I have 2 classes that I save one as I mentioned above full of integers, possible some strings. Also another separate from the one above Vector which contains a few classes of different types in no set order and the size changes based on the user deleting things, creating new ones, etc.
Contributor
Posts: 12
Registered: ‎06-16-2011
My Device: 9000
My Carrier: Vodafone

Re: Persitible Structure Change

Using IntHashtable It is very simple process and it will handle all the scenario.

 

Make a Class which will have all getter and setter of your specific.

Define your public static final int keys to mape your data.

Keep a object of intHashtable and initialy read it from Persistance if it is there then then assign else creat new and commit.

Now in your getter and setter read the object from IntHashtable for that specified key if its not there then return the default value and in each setter put the value on the key in IntHashtable and commit it.

 

Done Smiley Happy