lundi 28 décembre 2015

Android updating SQLite database from IntentService

I set my application up to store the users data in a SQLite database, and when they get a wifi connection a button appears on a screen refresh that lets them start an IntentService and upload the data to a AppEngine Datastore associated with the application. A result is returned from the datastore indicating success or failure. If successful the IntentService gets a reference to a SQLite database( with application context) and deletes the row. Most of the time this works well however if the user navigates out of the app, and the the app gets destroyed, the row data is not removed from the SQLite database.

  • I was thinking about switching to a ContentProvider, however I'm not sure if I can delete rows from the ContentProvider if the application is closed, which then wouldn't be any better than the SQLite database.
  • I could open the SQLite database with Intent Service Context, but then I wouldn't be able to use the singleton pattern, and I would have to deal with the database getting closed unexpectedly.
  • I could check the back-end to see if the data is present and then delete it on the front end if it is or upload it if it's not, but that doesn't seem like the most efficient way.

I'm wondering if anyone else has solved this type of problem and would like to share their solution with me?

Aucun commentaire:

Enregistrer un commentaire