title: How can we use cursor and access database in Service class in Android?
body: <p>I have an Sqlite database that has a collection of locations. And a continuously running service which runs in background and get location and compare with stored locations available in database.</p>
  
  <p>Currently I am reading data through SQLiteDatabase.query method which returns cursor.
  But application is crashing due to this (Already cursor closed error)</p>
  
  <p>My question is How can we access database or use cursor in service? 
  What would be the best way to use cursor in service?</p>
  
  <p>I don't know about content provider much. But have doubt that I need to implement ContentProvider for this purpose.</p>
  
  <p>I am stuck here. Please guide me for this.</p>
  
  <p>Thanks in Advance.</p>
  
  <p><strong>Update</strong>
  My code is look like</p>
  
  <pre><code>public void onLocationChanged(Location currentLocation)
  {
      Log.d(TAG, "Location Updated");
  
      latitude = currentLocation.getLatitude();
      longitude = currentLocation.getLongitude();
  
      Cursor cursor = mDatabaseManager.getAllLocations();
      // Do something
      cursor.close();
  }
  </code></pre>
  
  <p>This method means location change callback is implemented in service class.</p>