Chapter 17. Cursors and Asynctasks: Staying in the Background

In most apps, you’ll need your app to update its data.

So far you’ve seen how to create apps that read data from a SQLite database. But what if you want to update the app’s data? In this chapter you’ll see how to get your app to respond to user input and update values in the database. You’ll also find out how to refresh the data that’s displayed once it’s been updated. Finally, you’ll see how writing efficient multithreaded code with AsyncTasks will keep your app speedy.

We want our Starbuzz app to update database data

In Chapter 16, you learned how to change your app to read its data from a SQLite database. You saw how to read an individual record (a drink from the Starbuzz data) and display that record’s data in an activity. You also learned how to populate a list view with database data (in this case drink names) using a cursor adapter.

In both of these scenarios, you only needed to read data from the database. But what if you want users to be able to update the data?

We’re going to change the Starbuzz app so that users can record which drinks are their favorites. We’ll do this by adding a checkbox to DrinkActivity; if it’s checked, it means the current drink is one of the user’s favorites:

We’ll also add a new list view to ...

Get Head First Android Development, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.