Android Storage

apatheticyogurtSoftware and s/w Development

Dec 13, 2013 (3 years and 7 months ago)

83 views

Android Storage

MAY 2013

Hu.Cai


NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

Outline

1.
Storage In General

2.
SharedPreferences

3.
File

4.
Database

5.
External Storage(
SDCard

and Network)


2

NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

1
. Storage In General

3

APP Storage

Internal

SharedPreferences

File

Database

External

SDCard

Network

NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

2.
SharedPreferences






4


Store private primitive data in key
-
value pairs,


data type include:
boolean,int,float,long,string



This data will persist across user sessions, even if
your application is killed


NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

SharedPreferences

Sample

5

Activity
-

A, write data

Activity
-

B, read data

NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

SharedPreferences

Sample

6

/data /data/
package_name
/
shared_prefs
/config.xml

conclusion
: light
-
weight option

NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

3. File






7


Store private data on the device memory.



When the user uninstalls your app, these files are
removed.


NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

Internal Storage
Sample

-

File

8

Activity
-

A, write data

Activity
-

B, read data

NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

Internal Storage
Sample

-

File

9

/data /data/
package_name
/files/test.txt

conclusion
: middle
-
weight option, depends on the space of your
mobile internal storage.

NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

4. Database






10


Store structured data in a private database.



Any databases you create will be accessible by
name to any class in the application, but not
outside the application.

NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

SQLite






11


SQLite

is a software library that implements a
self
-
containe
d
,
serverless
,
zero
-
configuration
,
transactional

SQL database engine.

NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

SQLite






12

I
mplements
most of the SQL
-
92
standard for
SQL but it lacks some features.


1.
P
artial support for triggers.

2.
Can't write to views(
delete,insert,update
).

3.
Can’t support
full outer join , right outer join


4.
Support limit to return records .

5.
Case
-
sensitive


NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

SQLite




Create or Open database


SQLiteDatabase

openOrCreateDatabase

(String
name,int

mode,
SQLiteDatabase.CursorFactory

factory)


MODE_PRIVATE,MODE_WORLD_ READABLE,MODE_WORLD_WRITEABLE



Execute non
-
query SQL



execSQL
(String
sql
), support
insert,update,delete,create,drop

SQL.



Execute query SQL


rawQuery
(String
sql
), support select SQL.



Cursor to keep track of location within a
resultset








13

NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

SQLite

CRUD
-

SQLiteDatabase

methods


public long
insert

(String table, String
nullColumnHack
,
ContentValuesinitialValues
).



delete
(String table, String
whereClause
, String[]
whereArgs
)



query
(String table, String[] columns, String selection, String[]
selectionArgs
, String
groupBy
, String having, String
orderBy
, String limit)



update
(String table,
ContentValues

values, String
whereClause
, String[]
whereArgs
)






14

NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

SQLite

Sample

15

NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

SQLite

Sample

16

NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

5. External Storage(
SDCard

and Network)






17


Store public data on the shared external storage.



T
his can be a removable storage media (such as
an SD card) or an internal (non
-
removable)
storage.

NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

SDCard

Storage
Sample

18

Activity
-

A, write data

Activity
-

B, read data

NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

SDCard

Storage
Sample

19

/
mnt
/
sdcard
/sd.txt

conclusion
: you can write larger
data to file. Such as a game application.

NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

Network Storage






20


Store data on the web with your own network
server.



Web service , HTTP



java.net.*

Android.net.*



NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

Which is the best way to store it ?







21

1.
How often will the data be accessed or updated?

2.
The data is private?

3.
Will the data be added to over time?

4.
How will the data need to be used?

5.
How much space your data requires?



NAME OF PRESENTATION [CHANGE IN SLIDE MASTER]

MONTH, YEAR [CHANGE IN SLIDE MASTER]

22

© 2009 Moody’s Analytics, Inc. and/or its licensors and affiliates (collectively, “MOODY’S”). All rights reserved. ALL INFORM
ATI
ON CONTAINED HEREIN IS PROTECTED BY
COPYRIGHT LAW AND NONE OF SUCH INFORMATION MAY BE COPIED OR OTHERWISE REPRODUCED, REPACKAGED, FURTHER TRANSMITTED, TRANSFERRE
D,
DISSEMINATED, REDISTRIBUTED OR RESOLD, OR STORED FOR SUBSEQUENT USE FOR ANY SUCH PURPOSE, IN WHOLE OR IN PART, IN ANY FORM OR

MA
NNER OR
BY ANY MEANS WHATSOEVER, BY ANY PERSON WITHOUT MOODY’S PRIOR WRITTEN CONSENT. All information contained herein is obtained by

MO
ODY’S from sources
believed by it to be accurate and reliable. Because of the possibility of human or mechanical error as well as other factors,

ho
wever, all information contained herein is provided “AS
IS” without warranty of any kind. Under no circumstances shall MOODY’S have any liability to any person or entity for (a) any

lo
ss or damage in whole or in part caused by, resulting
from, or relating to, any error (negligent or otherwise) or other circumstance or contingency within or outside the control o
f M
OODY’S or any of its directors, officers, employees or
agents in connection with the procurement, collection, compilation, analysis, interpretation, communication, publication or d
eli
very of any such information, or (b) any direct, indirect,
special, consequential, compensatory or incidental damages whatsoever (including without limitation, lost profits), even if M
OOD
Y’S is advised in advance of the possibility of such
damages, resulting from the use of or inability to use, any such information. The ratings, financial reporting analysis, proj
ect
ions, and other observations, if any, constituting part of
the information contained herein are, and must be construed solely as, statements of opinion and not statements of fact or re
com
mendations to purchase, sell or hold any securities.
NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE ACCURACY, TIMELINESS, COMPLETENESS, MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR
PUR
POSE OF
ANY SUCH RATING OR OTHER OPINION OR INFORMATION IS GIVEN OR MADE BY MOODY’S IN ANY FORM OR MANNER WHATSOEVER. Each rating or
oth
er opinion must
be weighed solely as one factor in any investment decision made by or on behalf of any user of the information contained here
in,

and each such user must accordingly make its own
study and evaluation of each security and of each issuer and guarantor of, and each provider of credit support for, each secu
rit
y that it may consider purchasing, holding, or selling.