As the docs say, the onRetainNonConfigurationInstance() should only be used
as an optimization, not to replace a working implementation of the normal
onSaveInstanceState() et al mechanism.  (The latter is the only thing that
can be done in the case where an app's process needs to be killed or its
activities removed while in the background, which is what destroying
activities immediately emulates.)

At any rate, you should be able to put a styled CharSequence into a bundle
(or use the TextUtils class to write it directly to a Parcel) and get it out
again with the styling intact.  Unfortunately this currently only works for
the built-in styleable classes, so if you need to retain your own custom
ones you will probably do your own marshalling/unmarshalling with the
Parcel.

On Tue, Dec 30, 2008 at 9:51 AM, Al <[email protected]> wrote:

>
> I did read your site posts before deciding how to saving data when
> rotating, but the problem is onRetain....() isn't called, for example,
> when you set the emulator to destroy activities immediately and then
> press 'Home'. OnSave....() on the other hand *is* called. Because of
> this, I've decided to save the text in onSave...() instead, but I
> can't preserve formatting.
>
> On Dec 30, 12:34 am, Mark Murphy <[email protected]> wrote:
> > Al wrote:
> > > My app uses colour on some of the strings it writes to the TextView.
> > > The problem I'm having is when I open/close the keyboard, I'm forced
> > > to save the coloured data as Strings, which means it loses formatting.
> > > The Bundle class doesn't support saving Objects so I've tried writing
> > > it to a Parcel and then storing it in a Bundle. But then it needs a
> > > ClassLoader to read the data back, and I'm not sure I need to pass to
> > > it. The TextView text is a mix of spannableStrings and plain 'ol
> > > String. Any pointers on saving the formatting between open/close
> > > keyboard cycle is appreciated.
> >
> > Don't use the Bundle, at least for rotations.
> >
> > There are plenty of alternative approaches, such as using
> > onRetainNonConfigurationInstance(). I have a five-post series on
> > AndroidGuys that covers this area:
> >
> > http://androidguys.com/?s=rotational+forces
> >
> > --
> > Mark Murphy (a Commons Guy)http://commonsware.com
> >
> > Android Training on the Ranch! -- Mar 16-20, 2009
> http://www.bignerdranch.com/schedule.shtml
> >
>


-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to