Bài giảng Lập trình cho thiết bị di động - Chương 3: Xử lý tập tin, lưu trạng thái ứng dụng, thao tác cơ sở dữ liệu và content provider - Trần Duy Thanh

DONG NAI UNIVERSITY OF TECHNOLOGY  
1. Files  
2. XML Parser  
3. Shared Preferences  
4. SQLite  
5. Content Provider  
1
DONG NAI UNIVERSITY OF TECHNOLOGY  
❑ Android Files  
➢ Uses the same file constructions found in a typical  
Java application  
➢ Files can be stored in the device’s (small) main  
memory or in the much larger SD card.  
➢ Files stored in the device’s memory, stay together  
with other application’s resources (such as icons,  
pictures, music, ). We will call this type: Resource  
Files.  
2
DONG NAI UNIVERSITY OF TECHNOLOGY  
❑ Data storage options  
➢ Shared Preferences Store private primitive data in  
key-value pairs.  
➢ Internal Storage Store private data on the device’s  
memory.  
➢ External Storage Store public data on the shared  
external storage.  
➢ SQLite Databases Store structured data in a  
private/public database.  
➢ Network Connection Store data on the web with  
your own network server.  
3
DONG NAI UNIVERSITY OF TECHNOLOGY  
1. Files  
1.1 Internal Storage  
1.2 External Storage  
1.3 Saving Cache files  
4
DONG NAI UNIVERSITY OF TECHNOLOGY  
1.1 Internal Storage  
Reading Resource File : Everything in the apk will be read only.  
And it's even better: android doesn't extract the apk when you  
install a program, so the size consumed is kept to minimal.  
5
DONG NAI UNIVERSITY OF TECHNOLOGY  
Reading Resource File  
1.1 Internal Storage  
6
DONG NAI UNIVERSITY OF TECHNOLOGY  
1.1 Internal Storage  
If you want to Read and Write an internal file:  
File is stored in the phone’s memory under:  
/data/data/app/files  
7
DONG NAI UNIVERSITY OF TECHNOLOGY  
Reading an internal File  
1.1 Internal Storage  
8
DONG NAI UNIVERSITY OF TECHNOLOGY  
Writing an internal File  
1.1 Internal Storage  
9
DONG NAI UNIVERSITY OF TECHNOLOGY  
1.2 External Storage  
Reading/Writing to External Device’s SD card. SD card  
has the obvious advantage of a larger working space.  
10  
DONG NAI UNIVERSITY OF TECHNOLOGY  
1.2 External Storage  
Reading  
11  
DONG NAI UNIVERSITY OF TECHNOLOGY  
1.2 External Storage  
Writing  
12  
DONG NAI UNIVERSITY OF TECHNOLOGY  
1.3 Saving Cache files  
To speed up your application’s performance and how often it  
accesses the network➔create a cache file.  
Cache files are stored in the following location on the Android  
file system:  
/data/data/app/cache  
Click icon to  
pull or push file  
13  
DONG NAI UNIVERSITY OF TECHNOLOGY  
1.3 Saving Cache files  
➢ If you'd like to cache some data, rather than store it  
persistently, you should use getCacheDir() to open a File  
that represents the internal directory where your  
application should save temporary cache files.  
➢ When the device is low on internal storage space,  
Android may delete these cache files to recover space.  
However, you should not rely on the system to clean up  
these files for you. You should always maintain the cache  
files yourself and stay within a reasonable limit of space  
consumed, such as 1MB. When the user uninstalls your  
application, these files are removed.  
14  
DONG NAI UNIVERSITY OF TECHNOLOGY  
1.3 Saving Cache files  
Creating cache file  
15  
DONG NAI UNIVERSITY OF TECHNOLOGY  
1.3 Saving Cache files  
Reading cache file  
16  
DONG NAI UNIVERSITY OF TECHNOLOGY  
1.3 Saving Cache files  
Get all cache files  
17  
DONG NAI UNIVERSITY OF TECHNOLOGY  
2. XML Parser  
2.1 What’s XML?  
2.2 How is XML used?  
2.3 Parsing XML by DOM  
2.4 Parsing XML by SAX  
18  
DONG NAI UNIVERSITY OF TECHNOLOGY  
2.1 What’s XML?  
Extensible Markup Language (XML) is a set of rules for  
encoding documents in a readable form.  
Similar to HTML but <tagElements> are user-defined.  
It is defined in the XML Specification produced by the W3C.  
XML's design goals emphasize transparency, simplicity, and  
transportability over the Internet.  
Example of XML-based languages include: RSS , Atom,  
SOAP, and XHTML.  
Several office productivity tools default to XML format for  
internal data storage. Example: Microsoft Office,  
OpenOffice.org, and Apple's iWork.  
19  
DONG NAI UNIVERSITY OF TECHNOLOGY  
2.2 How is XML used?  
XML is used for defining and documenting object classes.  
For example, an XML document (.xml) might contain a  
collection of complex employee elements, such as  
<employee id=“…” title=“…” >...</employee> which  
lexically includes an “id” and “title” attributes.  
Employee may also hold other inner elements such as  
“name”, “country”, “city”, and “zip”.  
An XML-Data schema (.xsd) can describe such syntax.  
20  
Tải về để xem bản đầy đủ
pptx 98 trang baolam 53080 Free
Bạn đang xem 20 trang mẫu của tài liệu "Bài giảng Lập trình cho thiết bị di động - Chương 3: Xử lý tập tin, lưu trạng thái ứng dụng, thao tác cơ sở dữ liệu và content provider - Trần Duy Thanh", để tải tài liệu gốc về máy hãy click vào nút Download ở trên

File đính kèm:

  • pptxbai_giang_lap_trinh_cho_thiet_bi_di_dong_chuong_3_xu_ly_tap.pptx