you can store the data to database or serialize the object. I guess you need keep some data or do something after app has been stopped.
On 6月2日, 上午9时03分, Dianne Hackborn <[email protected]> wrote: > If your process is killed, the next time you run a fresh process must be > created and re-initialized. There is no way to get a "stale" pointer across > this. If the pointer was stale, you'd probably have a native crash because > it would be completely unrelated to the current process you are running. > > You can verify the behavior yourself just by using adb shell to kill your > process. > > > > > > > > > > On Wed, Jun 1, 2011 at 5:39 PM, Jake Colman <[email protected]> wrote: > > > I was pretty sure that I understood the Android lifecycle and how > > applications/processes might be start/stopped/removed and how that > > effects whether variables remain initialized. I am, however, seeing > > some funky behavior in my app such that I am afraid I have missed > > something. > > > I use a singleton pattern for some of my objects. That is, the > > constructor is private and you call a static getInstance() method to > > construct the object. The static instance variable is, of course, > > initialized to NULL which is the trigger for getInstance to know whether > > the object needs to be constructed. > > > I have learned that any code that calls getInstance() cannot assume that > > the object it has constructed continues to live in memory since my > > application might have been killed by Android. So throughout my code I > > always call getInstance() to ensure that I have a valid object. Am I > > correct in assuming that had I been killed that getInstance() will > > create a new object? In other words, will my static instance variable > > have been reset to NULL or might my factory method give me back a stale > > pointer? > > > ...Jake > > > -- > > Jake Colman -- Android Tinkerer > > > -- > > 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 > > -- > 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

