onRetainNonConfigurationInstance is useful for switching orientation,
however variables (static or not) do not survive when Android
sacrifices your app for the greater good. You must store values that
you need to persist when your activity falls whim to Android's
caprices.

You can read more about the Activity lifecycle here:
http://developer.android.com/guide/topics/fundamentals.html#actlife
and about onRetainNonConfigurationInstance here:
http://developer.android.com/reference/android/app/Activity.html#onRetainNonConfigurationInstance()
and about storage APIs here:http://developer.android.com/guide/topics/
data/data-storage.html (tip: SharedPreferences is the easiest).



Yusuf Saib
Android
·T· · ·Mobile· stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.



On Jul 9, 4:44 pm, Keith Wiley <[email protected]> wrote:
> Okay, thanks.  Hmmm...so, static class members are definitely always
> preserved through an orientation flip?  That's what you're saying?  I
> had observed this, but wasn't sure under what circumstances I could
> trust it.  For example, I assume that doesn't necessarily apply to
> other sorts of changes, such as switching to another app.  If an app
> goes to the background long enough and the user does enough other
> things with the device, it surely must get shunted from memory if the
> OS needs the RAM back, so in such a case statics would not survive the
> app coming back to the foreground, right?...unless the OS carefully
> squirrels the relevant data away (on the sd card?) and retrieves it
> later as the app is coming back to the foreground...but then what
> happens if there isn't enough storage for the OS to save the static
> data?
>
> Clarification is greatly appreciated...and if it is already fully
> documented somewhere then I apologize and you don't have to repeat
> here...although a doc reference would always be appreciated if that
> isn't too much trouble.  I'll do some relevant digging on my own as
> well.  These seem like very specific detailed questions and I'm not
> sure if they are fully explained in the docs or not.
>
> Thanks again.
>
> On Jul 9, 2:25 pm, Dianne Hackborn <[email protected]> wrote:
>
>
>
> > There is no need to subclass Application; I would highly recommend putting
> > all of this stuff in a global static, that is just read once when needed.
> > This way whatever current activity needs it can just get it without leading
> > a copy itself.  If the data really is specific to one activity, then
> > onRetainNonConfigurationInstance is a good way to go.
>
> > On Thu, Jul 9, 2009 at 2:06 PM, Keith Wiley <[email protected]> wrote:
>
> > > Thanks.  I also received a tip to subclass Application and use that
> > > somehow (I'm still looking into it).
>
> > > Cheers!
>
> > > On Jul 9, 2:02 pm, Streets Of Boston <[email protected]> wrote:
> > > > These two links don't work well (the parenthesis mess it up).
> > > > Look at the onRetainNonConfigurationInstance and
> > > > getLastNonConfigurationInstance methods.
>
> > > > On Jul 9, 5:00 pm, Streets Of Boston <[email protected]> wrote:
>
> > > > > Take a look at these two:
> > >http://developer.android.com/reference/android/app/Activity.html#onRe...()<http://developer.android.com/reference/android/app/Activity.html#onRe...>
>
> > >http://developer.android.com/reference/android/app/Activity.html#getL...()<http://developer.android.com/reference/android/app/Activity.html#getL...>
>
> > > > > On Jul 9, 4:30 pm, Keith Wiley <[email protected]> wrote:
>
> > > > > > I have an app that might build some rather large data structures in
> > > > > > RAM.  Is there any way at all for my app to respond to orientation
> > > > > > flips (either via keyboard flip or tilt-sensor rotation, I don't 
> > > > > > care
> > > > > > which) without having to save and restore the state?  It can take
> > > > > > quite a while to save the data structures out to the SD card and can
> > > > > > take quite a while again to read them back in.
>
> > > > > > Thanks.- Hide quoted text -
>
> > > > > - Show quoted text -
>
> > --
> > 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, and so won't reply to such e-mails.  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