Computer Science E-76
Building Mobile Applications
Lecture 6: [Android] Storage and Threads
March 5, 2012
Dan Armendariz
danallan@mit.edu
Preferences
Lightweight key-value pair store
Files
Read/write files dynamically
Databases
SQLite
Data Storage
Methods
2
http://developer.android.com/reference/android/app/Activity.html
Activity
Lifecycle
3
Read
Context.openFileInput()
returns FileInputStream
Write
Context.openFileOutput()
returns FileOutputStream
Data Storage
Files
4
adb shell
sqlite3 /data/data/<pkg>/databases/<db>
Data Storage
SQLite
5
SQLite
Relational Database
6
TABLES
CREATE
ALTER
DROP
ROWS
SELECT
INSERT
UPDATE
DELETE
SQL
Statements
7
UPDATE users
SET email = "help@cs76.net"
WHERE user_id = 4;
SQL
Statement Syntax
8
http://www.sqlite.org/docs.html
SQLite
Documentation
9
NULL
the null value
INTEGER
signed integer
REAL
8-byte IEEE floating point value
TEXT
Text string
BLOB
data stored exactly as input
SQLite
Storage Classes
10
TEXT
stores NULL, TEXT, or BLOB
NUMERIC
any of the 5 classes
INTEGER
same as above*
REAL
same as numeric, but forces float
NONE
no storage class preferred
* - Except when converting a float to an integer
SQLite
Type Affinities
11
1. If type contains "INT", assigned INTEGER affinity.
2. If type contains "CHAR", "CLOB", "TEXT", then column is
given TEXT affinity.
3. If type contains "BLOG", column is given affinity NONE.
4. Type containing "REAL", "FLOA", "DOUB", given an affinity of
REAL.
5. Otherwise, affinity is NUMERIC.
From: http://www.sqlite.org/datatype3.html
SQLite
Column Affinities
12
By default, an app is
single-threaded
& single-process
As a result, heavy computation
will cause the UI to lock!
Threads
13
Computer Science E-76
Building Mobile Applications
Lecture 6: [Android] Storage and Threads
March 5, 2012
Dan Armendariz
danallan@mit.edu
14