Professional Documents
Culture Documents
1. Files
2. XML Parser
3. Shared Preferences
4. SQLite
5. Content Provider
Android Files
1. Files
1.1 Internal Storage
1.2 External Storage
1.3 Saving Cache files
Reading Resource
File
/data/data/app/files
Reading an internal
File
Writing an internal
File
10
Reading
11
Writing
12
13
14
15
16
17
2. XML Parser
2.1 Whats XML?
2.2 How is XML used?
2.3 Parsing XML by DOM
2.4 Parsing XML by SAX
18
20
21
22
23
24
25
Parsing this
XML
27
28
methods:
.getAttributeCount()
.getAttributeName()
.getAttributeValue()
29
30
31
32
33
3. Shared Preferences
3.1 Creating and Saving Preferences
3.2 Saving and Restoring Instance State
3.3 Shared Preference Change Listeners
3.4 Activity and Framework Preferences
34
35
Re open
application
information are
restored
36
37
38
39
The saving
location of
Preferences
XML format
40
41
42
43
45
46
48
51
52
SettingActivity
SettingActivity
MainActivity
4. SQLite
4.1 Introduction
4.2 Creating Database
4.3 Creating Table
4.4 Action Query:Insert, Update, Delete
4.5 Querying SQLite
4.6 Simple Database Demo
54
4.1 Introduction
Embedded standalone program called sqlite3
56
57
58
59
Inserting Records:
4.4 Action Query:Insert, Update, Delete
We use the insert() method to add new data to our tables.
We use the ContentValues object to pair the column names
to the column values for the record we want to insert.
60
Updating Records:
4.4 Action Query:Insert, Update, Delete
You can modify records in the database using the update()
method.The update() method takes four arguments:
The table to update records
A ContentValues object with the modified fields to update
An optional WHERE clause, in which ? identifies a
WHERE clause argument
An array of WHERE clause arguments, each of which is
substituted in place of the ?s from the second parameter
public int update (String table,
ContentValues values,
String whereClause, String[]
This
method Returns the number of rows
whereArgs)
affected
61
Updating Records:
4.4 Action Query:Insert, Update, Delete
Deleting Records:
4.4 Action Query:Insert, Update, Delete
You can remove records from the database using the remove()
method.The remove() method takes 3 arguments:
The table to delete the record from
An optional WHERE clause, in which ? identifies a WHERE
clause argument
An array of WHERE clause arguments, each of which is
substituted in place of the ?s from the second parameter
Passing null to the WHERE clause deletes all records in the
table.
public int delete (String table,
String whereClause,
String[] whereArgs)
This method Returns the number of rows
affected
63
Deleting Records:
4.4 Action Query:Insert, Update, Delete
Delete all rows in table tblop:
Delete row with malop=dhth7c:
64
65
columns
A list of which columns to return. Passing null will return all columns, which
is discouraged to prevent reading data from storage that isn't going to be
used.
selection
You may include ?s in selection, which will be replaced by the values from
selectionArgs selectionArgs, in order that they appear in the selection. The values will be
bound as Strings.
groupBy
having
A filter declare which row groups to include in the cursor, if row grouping is
being used, formatted as an SQL HAVING clause (excluding the HAVING
itself). Passing null will cause all row groups to be included, and is required
when row grouping is not being used.
orderBy
67
Transactiontake yourself
SQLiteOpenHelpertake yoursel
68
5. Content Provider
5.1 Introduction
5.2 Using common Content Provider
5.3 Create your own Content Provider
69
5.1 Introduction
content provider is a specialized type of
data store that exposes standardized ways
to retrieve and manipulate the stored data.
You wish to share data between
applications, you need to use the content
provider model as recommended in
Android.
most useful built-in content providers
70
72
73
74
75
76
77
78
79
80
83
DatabaseHelper class
5.3 Create your own Content Provider
84
Movie class
5.3 Create your own Content Provider
85
Movie class
5.3 Create your own Content Provider
86
Movie class
5.3 Create your own Content Provider
87
MyContentProvider cla
5.3 Create your own Content Provider
88
MyContentProvider cla
5.3 Create your own Content Provider
89
MyContentProvider cla
5.3 Create your own Content Provider
90
MainActivity XML
5.3 Create your own Content Provider
91
MainActivity class
5.3 Create your own Content Provider
92
MainActivity class
5.3 Create your own Content Provider
93
MainActivity class
5.3 Create your own Content Provider
94
MainActivity class
5.3 Create your own Content Provider
95
MainActivity class
5.3 Create your own Content Provider
96
Manifest XML
5.3 Create your own Content Provider
97
END
98