Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtaining Context for Geolocation within an 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).

My question is, how do I obtain context necessary to instantiate android.location.Geocoder from within an IntentService?

like image 289
mjsalinger Avatar asked Dec 26 '22 14:12

mjsalinger


1 Answers

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

like image 60
Flávio Faria Avatar answered Dec 29 '22 03:12

Flávio Faria