获取上下文进行地理定位的IntentService内 [英] Obtaining Context for Geolocation within an IntentService
问题描述
我创建一个Android类库,使呼叫转移至内线REST API和还采用了Android的地理codeR类(特别getFromLocation())需要上下文。我打算使库中IntentService允许它被异步运行,但我无法弄清楚如何处理上下文(GeoLoc调用是在一个单独的类,它是该IntentService调用库的一部分)。
I am creating an Android Class library that makes calls to an internal REST API and also utilizes Android's Geocoder class (specifically getFromLocation()) which requires Context. I was planning on making the library an IntentService to allow for it to be run asynchronously, but I can't figure out how to handle Context (the GeoLoc call is in a separate class that is part of the library that the IntentService calls).
我的问题是,如何从一个IntentService内获得必要的实例android.location.Geo codeR背景?
My question is, how do I obtain context necessary to instantiate android.location.Geocoder from within an IntentService?
推荐答案
每个服务
是 上下文
。您可以使用这个
或 getApplicationContext()
。
Every Service
is a Context
. You can use this
or getApplicationContext()
.
这篇关于获取上下文进行地理定位的IntentService内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!