Storing a spanned variable

Put your problem here if it does not fit any of the other categories.

Storing a spanned variable

Postby Sigma » Fri Jan 07, 2011 5:49 pm

I'm using Spanned variables to store formatted text, but I've noticed that it's quite slow to convert them to strings using Html.toHtml and then back with Html.fromHtml when I wish to store them, either in savedInstancestate when the phone is rotated or in Sharedpreferences.

Is there anyway to store the spanned variables directly without the costly conversion?
Or are there perhaps faster alternatives to the Html-functions?
Sigma
Developer
Developer
 
Posts: 33
Joined: Thu Dec 16, 2010 12:34 pm

Top

Re: Storing a spanned variable

Postby Skiller » Sun Jan 09, 2011 6:33 pm

If it's just to deal with orientation changes look into onRetainNonConfigurationInstance and getLastNonConfigurationInstance as they are what you are supposed to be using to deal with saving data between orientation changes.
Skiller
Developer
Developer
 
Posts: 33
Joined: Sun Nov 28, 2010 8:35 pm
Location: Australia

Re: Storing a spanned variable

Postby Sigma » Sun Jan 09, 2011 6:56 pm

Orientation issues are part of it, and those can be solved with your tip. There are some other circumstances though, for example when I want to save things using SharedPreferences for the application to remember until the next time it's started.
Sigma
Developer
Developer
 
Posts: 33
Joined: Thu Dec 16, 2010 12:34 pm

Re: Storing a spanned variable

Postby jonbonazza » Sun Jan 09, 2011 8:40 pm

Perhaps look into a configuration file?
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Re: Storing a spanned variable

Postby Sigma » Mon Jan 10, 2011 8:09 am

Will I be able to store a Spanned variable there without doing the costly conversation to String?
Sigma
Developer
Developer
 
Posts: 33
Joined: Thu Dec 16, 2010 12:34 pm

Re: Storing a spanned variable

Postby jonbonazza » Mon Jan 10, 2011 3:30 pm

well, since when writing to a file, you write the contents in binary form (as an array of bytes specifically), I don't see a need to convert to string.
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 16 guests