5. ACTIVITY TERMINATION
Starting from HoneyComb onwards, you can prepare for app termination in the
onStop.
If you are targeting pre-honeycomb, prepare for it as early as onPause
6. How to prepare for Termination
Close any connections or sockets
7.
8. Maintaining State
onSaveInstanceState called immediately before onPause
onRestoreInstanceState is called immediately after onCreate but only if
the app is being restarted after being terminated by the system
You can use these to restore your app the same state the user saw before their
exited the app
9. Storing Data in Android
Saves battery not to keep fetching data
Two Types:
1. SharedPreferences - using persistent key-value pairs for primitive data
types
2. Databases - Helps organise and find data easily
24. onUpgrade
Called when the database version has changed
Make sure to always change the version when you DB changes
If you modify the columns and add new ones, you might want to use the ALTER
TABLE command to add missing columns to the new DB
25. Read/Writting to the DB
Writing.
1. Get a reference to the Writable database
2. Create a ContentValues object of what you want to insert
3. Insert the content values and get back the row ID
Reading
1. All DB queries return cursor by default. A cursor is control structure that enables us to traverse
over the rows and columns of our result set
Editor's Notes
https://classroom.udacity.com/courses/ud853/lessons/3621368730/concepts/26026085410923
LINK TO SQL TUTORIAL
Also search on for storage types on the android documentation page
Functions to automate query building.
These represent a modular section of our DB solution
Implement the database using SQL
Connecting to the UI
An agreement between the data model, storage views and presentation describing how information is accesed.
Which columns should our contract have
Go to open helper code and explain
Note the NOT NULL contraints to avoid bugs
We start by calling cursor.moveToFirst();
Then close the cursor and database to release the system resources as soon as possible