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
Regular Contributor
IpiRon
Posts: 75
Registered: ‎10-19-2011
My Device: Developer
Accepted Solution

store byte[] in preferences??

I have various pieces of data that I successfully store in Prefs (PersistentObject and Hashtable). Currently I am only storing Strings and Integers (Which I convert to strings). I want to start storing encrypted data (byte[]) in the Preferences. What is the best way to implement? I'm drawing a blank on searches and I want to make sure my implementation doesn't just work today but then fails two months down the road. 

 

Thanks in advance!

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

Re: store byte[] in preferences??

Byte array is persistable as is.  Can you not just add it as an entry in your HashTable?

Regular Contributor
IpiRon
Posts: 75
Registered: ‎10-19-2011
My Device: Developer

Re: store byte[] in preferences??

Yeah, I thought about that on my dinner break. Since I'm a newbie, I wasn't real sure so I 'searched' but didn't see and outright example. The preference example I implemented in my app was one I found on the forums a while back and it has served me well with just strings and integers. I'll be playing with it shortly and post my results. Thanks! 

Regular Contributor
IpiRon
Posts: 75
Registered: ‎10-19-2011
My Device: Developer

Re: store byte[] in preferences??

Peter,

 

I did more due diligence and got it to work as you suggested. As a new newbie, (I don't have much experience using HashTables even in my Android development).

 

Thanks for the nudge!

 

 

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

Re: store byte[] in preferences??

I recommend them, even in Android development, though I think you typically use a different collection class, the Map, in Android.  Map is not available on BlackBerry.

 

If you are considering Hashtables in this way, can I recommend thst you use the IntHashtable - this says creating a new Object just for the Key.  Avoiding Objects, especially in persisted store, is a good thing. 

Regular Contributor
IpiRon
Posts: 75
Registered: ‎10-19-2011
My Device: Developer

Re: store byte[] in preferences??

I've only got 2 years Java exeperience. I'm a 10+ year VB developer normally. Nobody at our office wanted to learn Java so I was 'selected'.I'm still learning all the different 'critters' it supports. Thanks for the tip. I'll make it a point to improve on them!