Task 0. Download and run the starter code
Task 1. Extend SQLiteOpenHelper to create and populate a database
1.1 Create a skeleton WordListOpenHelper class
1.2. Add database constants to WordListOpenHelper
1.3. Build the SQL query and code to create the database
1.4 Create the database in onCreate of the MainActivity
1.5 Add data to the database
Task 2. Create a data model for a single word
2.1. Create a data model for your word data
Task 3. Implement the query() method in WordListOpenHelper
3.1. Implement the query() method
3.2. The onUpgrade method
Task 4. Display data in the RecyclerView
4.1. Update WordListAdapter to display WordItems
Task 5. Add new words to the database
5.1. Write the insert() method
5.2. Get the word to insert from the user and update the database
5.3. Implement getItemCount()
Task 6. Delete words from the database
6.1. Write the delete() method
6.2. Add a click handler to DELETE button
Task 7. Update words in the database
7.1. Write the update() method
7.2. Add a click listener to the EDIT button
7.3. Add updating to onActivityResult
7.4. Design and error considerations
- The methods you wrote to add, update and delete entries in the database all assume that their input is valid. This is acceptable for sample code because the purpose of this sample code is to teach you the basic functionality of a SQLite database, and so not every edge case is considered, not every value is tested, and everybody is assumed to be well behaved. If this were a production app, you would have greater security considerations, and content would need to be tested for validity until you know it is not malicious.
- In a production app, you must catch specific exceptions and handle them appropriately.
- You tested the correct functioning of the app by running it. For a production app with real data, you will need more thorough testing, for example, using unit and interface testing.
- For this practical, you created the the database schema/tables from the SQLiteOpenHelper class. This is sufficient for a simple example, like this one. For a more complex app, it is a better practice to separate the schema definitions from the rest of the code in a helper class that cannot be instantiated. You will learn how to do that in the chapter on content providers.
- As mentioned above, some database operations can be lengthy and should be done on a background thread. Use AsyncTask for operations that take a long time. Use loaders to load large amounts of data.
Leave a Reply