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
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor
Accepted Solution

Workaround for storing non persistable objects i persistent storage?

I am storing configuration data of various sorts in persistent storage XML definitions and other String data.

This data is read from a server when the app is installed and can also be requested by the user.

It is stored in a hashtable for simple retrieval and the hashtables are saved in persistable storage, Works nice.

Except for storing images that come in the format og png files and these are not persistable. Discovered that the hard way :-)

Is there a way to circumvent this problem? All this data comes in a zip file from the server and all is unzipped to the SDCard. So is there a way to "transform" or "wrap" these png files so they can be saved in persistent storage? Saving them on the SD Card is ok for a temporary storage but for "permanent" storage I would like to keep them in persistent storage.

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Please use plain text.
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor

Re: Workaround for storing non persistable objects i persistent storage?

[ Edited ]

I see that there is a possibillity to convert the image to string

 

String  work  = img.toString()

 

Can I get back the image from String?

 

Or

 

Is byte[]  persistable?  In that case I can save the byte[] file in the hashtable instead and skip the statement

 

"Image img2 = Image.createImage(bytedata,0, bytedata.length);"

 

until later when I need the image?

 

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Please use plain text.
Developer
Developer
CMY
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Workaround for storing non persistable objects i persistent storage?

I don't think arrays are persistable. You can try one of the IntHashtables, but why would you want to store images in persistant storage? That's potentially wasting the users available memory that can only be reclaimed by deleting your application or if the application removes the image data. I think storing them on the SD Card would be the best bet and just alert the user that the information is being stored on there and that it will need to be redownloaded if the SD Card is removed or switched.
Please use plain text.
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor

Re: Workaround for storing non persistable objects i persistent storage?

Arrays are persistable. At least String and long arrays. I use them already. Yoursuggestion about storing on the SD-card is valid. Complicates thing a bit only.

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Please use plain text.
Developer
simon_hain
Posts: 16,023
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Workaround for storing non persistable objects i persistent storage?

byte arrays should also be persistable.
you can use http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/system/EncodedImage.html#getDa... to get the bytes from an image, and you already mentioned how to get it back.

storing it in sqllite would work similar.
----------------------------------------------------------
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
Please use plain text.
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor

Re: Workaround for storing non persistable objects i persistent storage?

Tried byte[]. works fine.

 

I will generalize and use byte[] for both configs, xml-strings and Images when storing in hashtable since all are retrieved from the SDcard in byte[] format initially. When retrieving I convert to String or Image.

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Please use plain text.