0% found this document useful (0 votes)
24 views

Computer Science E-76 Building Mobile Applications

This document summarizes a lecture on storage and threads in Android applications. It discusses preferences, files, and SQLite databases for data storage. It also covers the Android activity lifecycle and methods for reading and writing files. The lecture explains how to use SQLite for data storage and SQL statements like CREATE, SELECT, and UPDATE. It provides documentation links and describes SQLite storage classes, type affinities, and column affinities. Finally, it notes that Android apps are single-threaded by default, which can cause the UI to lock during heavy computation, so threads are necessary.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Computer Science E-76 Building Mobile Applications

This document summarizes a lecture on storage and threads in Android applications. It discusses preferences, files, and SQLite databases for data storage. It also covers the Android activity lifecycle and methods for reading and writing files. The lecture explains how to use SQLite for data storage and SQL statements like CREATE, SELECT, and UPDATE. It provides documentation links and describes SQLite storage classes, type affinities, and column affinities. Finally, it notes that Android apps are single-threaded by default, which can cause the UI to lock during heavy computation, so threads are necessary.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Computer Science E-76

Building Mobile Applications

Lecture 6: [Android] Storage and Threads


March 5, 2012
Dan Armendariz
[email protected]

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 = "[email protected]"
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
[email protected]

14

You might also like