Getting context for geolocation in IntentService

I am creating an Android class library that makes calls in the internal REST API, and also uses the Geocoder class for Android (specifically getFromLocation ()), which requires Context. I planned to make the IntentService library so that it runs asynchronously, but I cannot figure out how to handle the Context (the GeoLoc call is in a separate class that is part of the library that IntentService calls).

My question is: how do I get the context needed to instantiate android.location.Geocoder from an IntentService?

+4
source share
2 answers

Each Service is a Context . You can use this or getApplicationContext() .

+10
source

IntentService Inherits Service and Services inherits context.

You can use "this" as a Context when you need it in an IntentService.

0
source

Source: https://habr.com/ru/post/1445614/


All Articles