We're in agreement then :)
I like how you use Application class in method signature to ensure
correctness (although I tend to call getApplicationContext inside
MySingleton).
-- Kostya
27.03.2011 20:36, Mark Murphy пишет:
My point was that you should not have:
class MySingleton {
Context thisIsAReallyBadIdea;
MySingleton(Context ctxt) {
thisIsAReallyBadIdea=ctxt;
}
// rest of class here
}
Instead, you should have:
class MySingleton {
Application thisIsMildlyDisconcertingButProbablyOK;
MySingleton(Application ctxt) {
thisIsMildlyDisconcertingButProbablyOK=ctxt;
}
// rest of class here
}
In other words, use Java's type safety to ensure that you are caching
an object with the appropriate lifetime, and that you are using it as
the object with the appropriate lifetime.
--
Kostya Vasilyev -- 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