4

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?

mjsalinger
  • 660
  • 6
  • 17

2 Answers2

10

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

Flávio Faria
  • 6,575
  • 3
  • 39
  • 59
0

IntentService Inherits Service, and Service Inherits Context.

You are free to use "this" as Context whenever you needs it inside your IntentService.

Shahul3D
  • 2,129
  • 1
  • 15
  • 16