Friday, January 18, 2013

[android-developers] Re: Application.onCreate Method Randomly Called?

>>>>> "MM" == Mark Murphy <mmurphy@commonsware.com> writes:

MM> On Fri, Jan 18, 2013 at 10:11 AM, Jake Colman <colman@ppllc.com> wrote:

>> Am I making a fundamental mistake in how this is supposed to be done?

MM> No, that all seems OK.

>> You've already told me that when the application is recreated it
>> gets a new context. If so, how are preferences persisted across
>> recreations of my application if the "key" to those preferences
>> are the context?

MM> The "key" to those preferences is the package name. An easy way
MM> to get the package name is by calling getPackageName() on a
MM> Context. The "key" to those preferences is not the Context
MM> itself.

MM> In this case, the "key" is used as the basis of a filename, for
MM> the XML file which contains the persisted SharedPreferences.

Ok. That makes sense but brings it all back full circle.

It's clear that Application.onCreate is being called multiple times for
my app. It also seems that my preferences are being reset as a result
of that happening. But from everything that I am reading in this
discussion it would seem that should not be the case. I guess I have to
add some debugging code and have my user side-load it to see if I can
get some insight into the problem.

Incidentally, this is a fairly straighforward application with nothing
fancy. It uses an AppWidget class, one Activity, a Preference
Activity and a Service to do some work on behalf of the widget. So any
whatever is causing my problem it's not because I am being too fancy.

--
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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment