I'm refactoring an app I made some time ago. Back then I was taking my first steps into Android and the easy way to go was to avoid orientation changes, for almost all my CRUD operations I used the AsyncTask class, didn't implement a Content Provider or used Fragments.
Now I have made some changes:
- I use
Fragments to encapsulate functionality - All accesses to my database are done through a
Content Provider - I use
CursorLoaders to retrieve my data taking advantage of the content observation and automatic background loading theLoaderFrameworkbrings.
The only problem I have now is that I'm not quite sure how to handle the rest of the CRUD operations (Create,Update, and Delete). I've found that I can use the AsyncQueryHandler class, but there's not enough information online. One thing I like the Loader Framework, is that is aware of the Activity or Fragment lifecycle, but what about the AsyncQueryHandler?
- What happens to the operations that were started with
startDelete,startInsert,startUpdatewhen theActivity/Fragmentundergoes a configuration change? Or when I press the back button? Or worse yet, if the activity is destroyed? - What is the expected behavior of this kind of operations in such cases? Should they be cancelled or should they continue to do their work?
All the operations I've mentioned above are not that complex. For real complex operations I've used Services or IntentServices, but since I don't consider a good idea to run SQLite operations on the main thread I want to use a better solution, but first I need to know how that solution should react to the Activity/Fragment lifecycle events.
Any comments or suggestions would me greatly appreciated. Thannks.
Aucun commentaire:
Enregistrer un commentaire