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

98 799 0
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

Đ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

HO CHI MINH UNIVERSITY OF INDUSTRY 1 5. Content Provider 4. SQLite 3. Shared Preferences 2. XML Parser 1. Files HO CHI MINH UNIVERSITY OF INDUSTRY 2  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.  Android Files HO CHI MINH UNIVERSITY OF INDUSTRY 3  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. HO CHI MINH UNIVERSITY OF INDUSTRY 4 1. Files 1.1 Internal Storage 1.2 External Storage 1.3 Saving Cache files HO CHI MINH UNIVERSITY OF INDUSTRY 5 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. HO CHI MINH UNIVERSITY OF INDUSTRY 6 1.1 Internal Storage Reading Resource File HO CHI MINH UNIVERSITY OF INDUSTRY 7 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 HO CHI MINH UNIVERSITY OF INDUSTRY 8 1.1 Internal Storage Reading an internal File HO CHI MINH UNIVERSITY OF INDUSTRY 9 1.1 Internal Storage Writing an internal File HO CHI MINH UNIVERSITY OF INDUSTRY 10 1.2 External Storage Reading/Writing to External Device’s SD card. SD card has the obvious advantage of a larger working space. [...]... document 30 HO CHI MINH UNIVERSITY OF INDUSTRY 2.4 Parsing XML by SAX 31 HO CHI MINH UNIVERSITY OF INDUSTRY 2.4 Parsing XML by SAX 32 HO CHI MINH UNIVERSITY OF INDUSTRY 2.4 Parsing XML by SAX 33 HO CHI MINH UNIVERSITY OF INDUSTRY 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 ... and “zip” An XML-Data schema (.xsd) can describe such syntax 20 HO CHI MINH UNIVERSITY OF INDUSTRY 2.2 How is XML used? 21 HO CHI MINH UNIVERSITY OF INDUSTRY 2 .3 Parsing XML by DOM DOM : W3C DocumentBuilder Parser Document Object Model Cache all Standard tree structure Parsing this XML 22 HO CHI MINH UNIVERSITY OF INDUSTRY 2 .3 Parsing XML by DOM The XML file is given to the W3C parser to construct... files are removed 14 HO CHI MINH UNIVERSITY OF INDUSTRY 1 .3 Saving Cache files Creating cache file 15 HO CHI MINH UNIVERSITY OF INDUSTRY 1 .3 Saving Cache files Reading cache file 16 HO CHI MINH UNIVERSITY OF INDUSTRY 1 .3 Saving Cache files Get all cache files 17 HO CHI MINH UNIVERSITY OF INDUSTRY 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 HO CHI MINH... Storage Writing 12 HO CHI MINH UNIVERSITY OF INDUSTRY 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 HO CHI MINH UNIVERSITY OF INDUSTRY 1 .3 Saving Cache files  If you'd like to cache some data,... from the XML file are represented in the parsetree as NodeLists These ArrayList-like collections are made with the getElementsByTagName() method An individual node from a NodeList could be explored using the methods: .item(i), getName() , getValue() , getFirstChild() , getAttributes(),… 23 HO CHI MINH UNIVERSITY OF INDUSTRY 2 .3 Parsing XML by DOM Creating a Java DOM XML parser is done using the javax.xml.parsers.DocumentBuilderFactory... 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 include: RSS , Atom, SOAP, and XHTML Several office productivity tools default to XML format... the Editor object by calling edit on the Shared Preferences object you want to change To save edits call commit on the Editor 35 HO CHI MINH UNIVERSITY OF INDUSTRY 3. 1 Creating and Saving Preferences Checked and then click Login Re open application information are restored 36 ... Creating a Java DOM XML parser is done using the javax.xml.parsers.DocumentBuilderFactory class Parsing an XML file into a DOM tree 24 HO CHI MINH UNIVERSITY OF INDUSTRY 2 .3 Parsing XML by DOM 25 HO CHI MINH UNIVERSITY OF INDUSTRY 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... 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 HO CHI MINH UNIVERSITY OF INDUSTRY 3. 1 Creating and Saving Preferences  To create or modify a Shared Preference, call getSharedPreferences on the application Context, passing in the name of the Shared Preference to change Shared Preferences... object The Document object has a single root element Element root = doc.getDocumentElement(); get the children of an element get the attribute of an element get the data of an element element.getTextContent(); 26 HO CHI MINH UNIVERSITY OF INDUSTRY 2.4 Parsing XML by SAX SAX Simple API for XML scan the document Less memory Faster Complex Parsing this XML 27 HO CHI MINH UNIVERSITY OF INDUSTRY . HO CHI MINH UNIVERSITY OF INDUSTRY 1 5. Content Provider 4. SQLite 3. Shared Preferences 2. XML Parser 1. Files HO CHI MINH UNIVERSITY OF INDUSTRY 2  . OF INDUSTRY 15 1 .3 Saving Cache files Creating cache file HO CHI MINH UNIVERSITY OF INDUSTRY 16 1 .3 Saving Cache files Reading cache file HO CHI MINH UNIVERSITY OF INDUSTRY 17 1 .3 Saving Cache. MINH UNIVERSITY OF INDUSTRY 12 1.2 External Storage Writing HO CHI MINH UNIVERSITY OF INDUSTRY 13 1 .3 Saving Cache files To speed up your application’s performance and how often it accesses the

Ngày đăng: 06/07/2014, 18:33

Từ khóa liên quan

Mục lục

  • Slide 1

  • Slide 2

  • Slide 3

  • Slide 4

  • Slide 5

  • Slide 6

  • Slide 7

  • Slide 8

  • Slide 9

  • Slide 10

  • Slide 11

  • Slide 12

  • Slide 13

  • Slide 14

  • Slide 15

  • Slide 16

  • Slide 17

  • Slide 18

  • Slide 19

  • Slide 20

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan