There is no "current application context." You should have the pass a context into you. If you can't do that, the only thing you can safely rely on is a context for just the base platform without being associated with an application.
On Tue, Sep 28, 2010 at 8:51 AM, Guy Rosen
<guy....@vircado.com> wrote:
Hi,
I'm in need of a context object from inside framework code. The
framework code in question doesn't have access to a context because it
is by definition not loaded explicitly by an app, but rather is listed
in frameworks/base/preloaded-classes. Because apps never call it
directly, there is no obvious opportunity to pass a Context to it (it
is called indirectly as it is registered to be called from some
java.net classes).
This code seems to work, but I wonder if it's the Right Thing to do
and if there are consequences I'm not aware of (a similar snippet
appears in the GeolocationService ctor).
ActivityThread activityThread =
ActivityThread.currentActivityThread();
if (activityThread == null) {
Looper.prepare(); // in case this hasn't been called yet -
otherwise systemMain() fails
activityThread = ActivityThread.systemMain();
}
applicationContext = activityThread.getApplication();
Any thoughts?
Thanks,
- Guy.
--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.
--
Dianne Hackborn
Android framework engineer
hac...@android.comNote: 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.