14.12.2010 22:24, Tobiah пишет:
I guess that's what I'm wondering. If Activity gets the context from
one of its superclasses, then can I get one some other way? I guess you
are saying that when I instantiate the Row class, I could just pass
'this'
to it from the Activity that I am using it from, then pass that to
the database instantiator in the Row class. Is that the best way to
get the context?
An Activity *is* a Context.
Is the context specific to the app, or to the activity?
Each Activity is a Context.
And since any Activity can go away as the user navigates the application
(switching activities), you shouldn't keep a reference to an Activity
(even cast to a Context) in any object that is supposed to have a long
lifespan, to avoid a memory leak.
This is a good case for calling Activity.getApplicationContext - it
returns a reference to Application, which is also a Context, and doesn't
go away until the application terminates.
Pass a Context into your object's constructors, call
getApplicationContext on that, and you can keep the returned value.
--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com
--
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