the android activity lifecycle
Post on 12-Apr-2017
99 Views
Preview:
TRANSCRIPT
THE ANDROID ACTIVITY LIFECYCLE
Active and Visible Lifetimes
The onPause
The onResume
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
How to prepare for Termination
Close any connections or sockets
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
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
Contract
WEATHER AND LOCATION TABLES
SQLite OPneHelper
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
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
Reading4. 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
top related