I am saving data on onPause method to SQLite database.
- I call
myObject.saveEntry(data). - It saves data by calling
AsyncTask.execute(new Runnable(){}) - Once data is saved, the callback method
savedSuccess(message)is called - An
ActivitymethodshowMessage(message)is called - A toast is shown saying the data is saved successfully
My doubt is on how to handle the orientation changes. When the orientation changes,
onPauseis called andsaveEntrymethod is called.- After that
onDestroyis called - A new instance of the Activity is created again.
- The
savedSuccess(message)method callback gets executed now (which was called from the previous instance of the Activity) showMessage(message)is called and toast is shown
My questions are
- Should I stop the
AsyncTaskfrom executing in theonDestroymethod - If not, how should I handle such situations when Activity gets destroyed before the database save/update/delete is complete?
Aucun commentaire:
Enregistrer un commentaire