1. Trang chủ
  2. » Công Nghệ Thông Tin

Bài giảng lập trình cho thiết bị di động chương 3 đh công ngệ đồng nai

98 615 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 98
Dung lượng 3,18 MB

Nội dung

DONG NAI UNIVERSITY OF TECHNOLOGY Files XML Parser Shared Preferences SQLite Content Provider 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 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 DONG NAI UNIVERSITY OF TECHNOLOGY Files 1.1 Internal Storage 1.2 External Storage 1.3 Saving Cache files 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 DONG NAI UNIVERSITY OF TECHNOLOGY 1.1 Internal Storage Reading Resource File 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 DONG NAI UNIVERSITY OF TECHNOLOGY 1.1 Internal Storage Reading an internal File DONG NAI UNIVERSITY OF TECHNOLOGY 1.1 Internal Storage Writing an internal File 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 5.3 Create your own Content Provider DatabaseHelper class 84 DONG NAI UNIVERSITY OF TECHNOLOGY 5.3 Create your own Content Provider Movie class 85 DONG NAI UNIVERSITY OF TECHNOLOGY 5.3 Create your own Content Provider Movie class 86 DONG NAI UNIVERSITY OF TECHNOLOGY 5.3 Create your own Content Provider Movie class 87 DONG NAI UNIVERSITY OF TECHNOLOGY 5.3 Create your own Content Provider MyContentProvider class 88 DONG NAI UNIVERSITY OF TECHNOLOGY 5.3 Create your own Content Provider MyContentProvider class 89 DONG NAI UNIVERSITY OF TECHNOLOGY 5.3 Create your own Content Provider MyContentProvider class 90 DONG NAI UNIVERSITY OF TECHNOLOGY 5.3 Create your own Content Provider MainActivity XML 91 DONG NAI UNIVERSITY OF TECHNOLOGY 5.3 Create your own Content Provider MainActivity class 92 DONG NAI UNIVERSITY OF TECHNOLOGY 5.3 Create your own Content Provider MainActivity class 93 DONG NAI UNIVERSITY OF TECHNOLOGY 5.3 Create your own Content Provider MainActivity class 94 DONG NAI UNIVERSITY OF TECHNOLOGY 5.3 Create your own Content Provider MainActivity class 95 DONG NAI UNIVERSITY OF TECHNOLOGY 5.3 Create your own Content Provider MainActivity class 96 DONG NAI UNIVERSITY OF TECHNOLOGY 5.3 Create your own Content Provider Manifest XML 97 DONG NAI UNIVERSITY OF TECHNOLOGY END 98 [...]... Parsing XML by SAX 32 DONG NAI UNIVERSITY OF TECHNOLOGY 2.4 Parsing XML by SAX 33 DONG NAI UNIVERSITY OF TECHNOLOGY 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 DONG NAI UNIVERSITY OF TECHNOLOGY 3. 1 Creating and Saving Preferences  To create or modify a Shared Preference,... 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... to other applications  To modify a Shared Preference use the SharedPreferences.Editor class Get the Editor object by calling edit on the Shared Preferences object you want to change To save edits call commit on the Editor 35 DONG NAI UNIVERSITY OF TECHNOLOGY 3. 1 Creating and Saving Preferences Checked and then click Login Re open application information are restored 36 ... schema (.xsd) can describe such syntax 20 DONG NAI UNIVERSITY OF TECHNOLOGY 2.2 How is XML used? 21 DONG NAI UNIVERSITY OF TECHNOLOGY 2 .3 Parsing XML by DOM DOM : W3C DocumentBuilder Parser Document Object Model Cache all Standard tree structure Parsing this XML 22 DONG NAI UNIVERSITY OF TECHNOLOGY 2 .3 Parsing XML by DOM The XML file is given to the W3C parser to construct an equivalent tree Elements... getElementsByTagName() method An individual node from a NodeList could be explored using the methods: .item(i), getName() , getValue() , getFirstChild() , getAttributes(),… 23 DONG NAI UNIVERSITY OF TECHNOLOGY 2 .3 Parsing XML by DOM Creating a Java DOM XML parser is done using the javax.xml.parsers.DocumentBuilderFactory class Parsing an XML file into a DOM tree 24 DONG NAI UNIVERSITY OF TECHNOLOGY 2 .3 Parsing XML by... DONG NAI UNIVERSITY OF TECHNOLOGY 2.4 Parsing XML by SAX Attributes from an element can be extracted using the methods: .getAttributeCount() .getAttributeName() .getAttributeValue() 29 DONG NAI UNIVERSITY OF TECHNOLOGY 2.4 Parsing XML by SAX Using the XmlPullParser class to generate scanner/parser to traverse an XML document 30 DONG NAI UNIVERSITY OF TECHNOLOGY 2.4 Parsing XML by SAX 31 DONG NAI. ..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... 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... 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 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... DOM XML parser is done using the javax.xml.parsers.DocumentBuilderFactory class Parsing an XML file into a DOM tree 24 DONG NAI UNIVERSITY OF TECHNOLOGY 2 .3 Parsing XML by DOM 25 DONG NAI UNIVERSITY OF TECHNOLOGY 2 .3 Parsing XML by DOM The two most commonly used features of DOM are: Accessing Child Elements of an Element Accessing Attributes of an Element At the top is the Document object The ... document 30 DONG NAI UNIVERSITY OF TECHNOLOGY 2.4 Parsing XML by SAX 31 DONG NAI UNIVERSITY OF TECHNOLOGY 2.4 Parsing XML by SAX 32 DONG NAI UNIVERSITY OF TECHNOLOGY 2.4 Parsing XML by SAX 33 DONG NAI. .. Preferences 37 DONG NAI UNIVERSITY OF TECHNOLOGY 3. 1 Creating and Saving Preferences 38 DONG NAI UNIVERSITY OF TECHNOLOGY 3. 1 Creating and Saving Preferences 39 DONG NAI UNIVERSITY OF TECHNOLOGY 3. 1... 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 DONG NAI UNIVERSITY

Ngày đăng: 04/12/2015, 02:14

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w