data storage
DESCRIPTION
Data Storage. Reference. http://developer.android.com/guide/topics/data/data-storage.html#pref http://marakana.com/forums/android/examples/63.html Hello Android, chapter 9. Overview. Shared Preferences Store private primitive data in key-value pairs. Internal Storage - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/1.jpg)
Data Storage
httpdeveloperandroidcomguidetopicsdatadata-storagehtmlpref
httpmarakanacomforumsandroidexamples63html
Hello Android chapter 9
Reference
Shared Preferences Store private primitive data in key-value pairs
Internal Storage Store private data on the device memory
External Storage Store public data on the shared external storage
SQLite Databases Store structured data in a private database
Network Connection Store data on the web with your own network
server
Overview
Shared PreferencesStore private primitive data in key-value pairs
How to save and retrieve data Using SharePrference class
persistent key-value pairs only primitive data types
booleans floats ints longs and strings This data will persist across user sessions
even if your application is killed
SharedPreferences Class
Get SharedPreferences object getSharedPreferences()
Use this if you need multiple preferences files identified by name which you specify with the first parameter
getPreferences() Use this if you need only one preferences file for
your Activity Because this will be the only preferences file for your Activity you dont supply a name
Write Call edit() to get a SharedPreferencesEditor Add values with methods such as putBoolean()
and putString() Commit the new values with commit()
Read use SharedPreferences methods such as
getBoolean() and getString()
To writeRead values
Using the Internal Storage
Store private data on the device memory
You can save files directly on the devices internal storage
By default files saved to the internal storage are private to your application and other applications cannot access them (nor can the user)
When the user uninstalls your application these files are removed
Internal Storage
Call openFileOutput() with the name of the file and the operating mode This returns a FileOutputStream
Write to the file with write() Close the stream with close()
Write to files
Call openFileInput() and pass it the name of the file to read This returns a FileInputStream
Read bytes from the file with read() Then close the stream with close()
Read files
XML file resources
XML resources can mean resources in general that are defined in XML layout files styles arrays resxml XML files
In this section we will be dealing with resxml XML files
XML resources
Hello DatabaseSQLite Databases
A tiny yet powerful database engine created by Dr Richard Hipp in 2000
It is arguably the most widely deployed SQL database engine in the world
Besides Android SQLite can be found in the Apple iPhone Symbian phones Mozilla Firefox Skype PHP Adobe AIR Mac OS X Solaris and many other places
SQLite
Itrsquos free The authors have placed it in the public domain
and donrsquot charge for its use Itrsquos small
The current version is about 150KB well within the memory budget of an Android phone
It requires no setup or administration There is no server no config file and no need for
a database administrator
Why SQLite
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 2: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/2.jpg)
httpdeveloperandroidcomguidetopicsdatadata-storagehtmlpref
httpmarakanacomforumsandroidexamples63html
Hello Android chapter 9
Reference
Shared Preferences Store private primitive data in key-value pairs
Internal Storage Store private data on the device memory
External Storage Store public data on the shared external storage
SQLite Databases Store structured data in a private database
Network Connection Store data on the web with your own network
server
Overview
Shared PreferencesStore private primitive data in key-value pairs
How to save and retrieve data Using SharePrference class
persistent key-value pairs only primitive data types
booleans floats ints longs and strings This data will persist across user sessions
even if your application is killed
SharedPreferences Class
Get SharedPreferences object getSharedPreferences()
Use this if you need multiple preferences files identified by name which you specify with the first parameter
getPreferences() Use this if you need only one preferences file for
your Activity Because this will be the only preferences file for your Activity you dont supply a name
Write Call edit() to get a SharedPreferencesEditor Add values with methods such as putBoolean()
and putString() Commit the new values with commit()
Read use SharedPreferences methods such as
getBoolean() and getString()
To writeRead values
Using the Internal Storage
Store private data on the device memory
You can save files directly on the devices internal storage
By default files saved to the internal storage are private to your application and other applications cannot access them (nor can the user)
When the user uninstalls your application these files are removed
Internal Storage
Call openFileOutput() with the name of the file and the operating mode This returns a FileOutputStream
Write to the file with write() Close the stream with close()
Write to files
Call openFileInput() and pass it the name of the file to read This returns a FileInputStream
Read bytes from the file with read() Then close the stream with close()
Read files
XML file resources
XML resources can mean resources in general that are defined in XML layout files styles arrays resxml XML files
In this section we will be dealing with resxml XML files
XML resources
Hello DatabaseSQLite Databases
A tiny yet powerful database engine created by Dr Richard Hipp in 2000
It is arguably the most widely deployed SQL database engine in the world
Besides Android SQLite can be found in the Apple iPhone Symbian phones Mozilla Firefox Skype PHP Adobe AIR Mac OS X Solaris and many other places
SQLite
Itrsquos free The authors have placed it in the public domain
and donrsquot charge for its use Itrsquos small
The current version is about 150KB well within the memory budget of an Android phone
It requires no setup or administration There is no server no config file and no need for
a database administrator
Why SQLite
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 3: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/3.jpg)
Shared Preferences Store private primitive data in key-value pairs
Internal Storage Store private data on the device memory
External Storage Store public data on the shared external storage
SQLite Databases Store structured data in a private database
Network Connection Store data on the web with your own network
server
Overview
Shared PreferencesStore private primitive data in key-value pairs
How to save and retrieve data Using SharePrference class
persistent key-value pairs only primitive data types
booleans floats ints longs and strings This data will persist across user sessions
even if your application is killed
SharedPreferences Class
Get SharedPreferences object getSharedPreferences()
Use this if you need multiple preferences files identified by name which you specify with the first parameter
getPreferences() Use this if you need only one preferences file for
your Activity Because this will be the only preferences file for your Activity you dont supply a name
Write Call edit() to get a SharedPreferencesEditor Add values with methods such as putBoolean()
and putString() Commit the new values with commit()
Read use SharedPreferences methods such as
getBoolean() and getString()
To writeRead values
Using the Internal Storage
Store private data on the device memory
You can save files directly on the devices internal storage
By default files saved to the internal storage are private to your application and other applications cannot access them (nor can the user)
When the user uninstalls your application these files are removed
Internal Storage
Call openFileOutput() with the name of the file and the operating mode This returns a FileOutputStream
Write to the file with write() Close the stream with close()
Write to files
Call openFileInput() and pass it the name of the file to read This returns a FileInputStream
Read bytes from the file with read() Then close the stream with close()
Read files
XML file resources
XML resources can mean resources in general that are defined in XML layout files styles arrays resxml XML files
In this section we will be dealing with resxml XML files
XML resources
Hello DatabaseSQLite Databases
A tiny yet powerful database engine created by Dr Richard Hipp in 2000
It is arguably the most widely deployed SQL database engine in the world
Besides Android SQLite can be found in the Apple iPhone Symbian phones Mozilla Firefox Skype PHP Adobe AIR Mac OS X Solaris and many other places
SQLite
Itrsquos free The authors have placed it in the public domain
and donrsquot charge for its use Itrsquos small
The current version is about 150KB well within the memory budget of an Android phone
It requires no setup or administration There is no server no config file and no need for
a database administrator
Why SQLite
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 4: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/4.jpg)
Shared PreferencesStore private primitive data in key-value pairs
How to save and retrieve data Using SharePrference class
persistent key-value pairs only primitive data types
booleans floats ints longs and strings This data will persist across user sessions
even if your application is killed
SharedPreferences Class
Get SharedPreferences object getSharedPreferences()
Use this if you need multiple preferences files identified by name which you specify with the first parameter
getPreferences() Use this if you need only one preferences file for
your Activity Because this will be the only preferences file for your Activity you dont supply a name
Write Call edit() to get a SharedPreferencesEditor Add values with methods such as putBoolean()
and putString() Commit the new values with commit()
Read use SharedPreferences methods such as
getBoolean() and getString()
To writeRead values
Using the Internal Storage
Store private data on the device memory
You can save files directly on the devices internal storage
By default files saved to the internal storage are private to your application and other applications cannot access them (nor can the user)
When the user uninstalls your application these files are removed
Internal Storage
Call openFileOutput() with the name of the file and the operating mode This returns a FileOutputStream
Write to the file with write() Close the stream with close()
Write to files
Call openFileInput() and pass it the name of the file to read This returns a FileInputStream
Read bytes from the file with read() Then close the stream with close()
Read files
XML file resources
XML resources can mean resources in general that are defined in XML layout files styles arrays resxml XML files
In this section we will be dealing with resxml XML files
XML resources
Hello DatabaseSQLite Databases
A tiny yet powerful database engine created by Dr Richard Hipp in 2000
It is arguably the most widely deployed SQL database engine in the world
Besides Android SQLite can be found in the Apple iPhone Symbian phones Mozilla Firefox Skype PHP Adobe AIR Mac OS X Solaris and many other places
SQLite
Itrsquos free The authors have placed it in the public domain
and donrsquot charge for its use Itrsquos small
The current version is about 150KB well within the memory budget of an Android phone
It requires no setup or administration There is no server no config file and no need for
a database administrator
Why SQLite
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 5: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/5.jpg)
How to save and retrieve data Using SharePrference class
persistent key-value pairs only primitive data types
booleans floats ints longs and strings This data will persist across user sessions
even if your application is killed
SharedPreferences Class
Get SharedPreferences object getSharedPreferences()
Use this if you need multiple preferences files identified by name which you specify with the first parameter
getPreferences() Use this if you need only one preferences file for
your Activity Because this will be the only preferences file for your Activity you dont supply a name
Write Call edit() to get a SharedPreferencesEditor Add values with methods such as putBoolean()
and putString() Commit the new values with commit()
Read use SharedPreferences methods such as
getBoolean() and getString()
To writeRead values
Using the Internal Storage
Store private data on the device memory
You can save files directly on the devices internal storage
By default files saved to the internal storage are private to your application and other applications cannot access them (nor can the user)
When the user uninstalls your application these files are removed
Internal Storage
Call openFileOutput() with the name of the file and the operating mode This returns a FileOutputStream
Write to the file with write() Close the stream with close()
Write to files
Call openFileInput() and pass it the name of the file to read This returns a FileInputStream
Read bytes from the file with read() Then close the stream with close()
Read files
XML file resources
XML resources can mean resources in general that are defined in XML layout files styles arrays resxml XML files
In this section we will be dealing with resxml XML files
XML resources
Hello DatabaseSQLite Databases
A tiny yet powerful database engine created by Dr Richard Hipp in 2000
It is arguably the most widely deployed SQL database engine in the world
Besides Android SQLite can be found in the Apple iPhone Symbian phones Mozilla Firefox Skype PHP Adobe AIR Mac OS X Solaris and many other places
SQLite
Itrsquos free The authors have placed it in the public domain
and donrsquot charge for its use Itrsquos small
The current version is about 150KB well within the memory budget of an Android phone
It requires no setup or administration There is no server no config file and no need for
a database administrator
Why SQLite
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 6: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/6.jpg)
Get SharedPreferences object getSharedPreferences()
Use this if you need multiple preferences files identified by name which you specify with the first parameter
getPreferences() Use this if you need only one preferences file for
your Activity Because this will be the only preferences file for your Activity you dont supply a name
Write Call edit() to get a SharedPreferencesEditor Add values with methods such as putBoolean()
and putString() Commit the new values with commit()
Read use SharedPreferences methods such as
getBoolean() and getString()
To writeRead values
Using the Internal Storage
Store private data on the device memory
You can save files directly on the devices internal storage
By default files saved to the internal storage are private to your application and other applications cannot access them (nor can the user)
When the user uninstalls your application these files are removed
Internal Storage
Call openFileOutput() with the name of the file and the operating mode This returns a FileOutputStream
Write to the file with write() Close the stream with close()
Write to files
Call openFileInput() and pass it the name of the file to read This returns a FileInputStream
Read bytes from the file with read() Then close the stream with close()
Read files
XML file resources
XML resources can mean resources in general that are defined in XML layout files styles arrays resxml XML files
In this section we will be dealing with resxml XML files
XML resources
Hello DatabaseSQLite Databases
A tiny yet powerful database engine created by Dr Richard Hipp in 2000
It is arguably the most widely deployed SQL database engine in the world
Besides Android SQLite can be found in the Apple iPhone Symbian phones Mozilla Firefox Skype PHP Adobe AIR Mac OS X Solaris and many other places
SQLite
Itrsquos free The authors have placed it in the public domain
and donrsquot charge for its use Itrsquos small
The current version is about 150KB well within the memory budget of an Android phone
It requires no setup or administration There is no server no config file and no need for
a database administrator
Why SQLite
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 7: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/7.jpg)
Write Call edit() to get a SharedPreferencesEditor Add values with methods such as putBoolean()
and putString() Commit the new values with commit()
Read use SharedPreferences methods such as
getBoolean() and getString()
To writeRead values
Using the Internal Storage
Store private data on the device memory
You can save files directly on the devices internal storage
By default files saved to the internal storage are private to your application and other applications cannot access them (nor can the user)
When the user uninstalls your application these files are removed
Internal Storage
Call openFileOutput() with the name of the file and the operating mode This returns a FileOutputStream
Write to the file with write() Close the stream with close()
Write to files
Call openFileInput() and pass it the name of the file to read This returns a FileInputStream
Read bytes from the file with read() Then close the stream with close()
Read files
XML file resources
XML resources can mean resources in general that are defined in XML layout files styles arrays resxml XML files
In this section we will be dealing with resxml XML files
XML resources
Hello DatabaseSQLite Databases
A tiny yet powerful database engine created by Dr Richard Hipp in 2000
It is arguably the most widely deployed SQL database engine in the world
Besides Android SQLite can be found in the Apple iPhone Symbian phones Mozilla Firefox Skype PHP Adobe AIR Mac OS X Solaris and many other places
SQLite
Itrsquos free The authors have placed it in the public domain
and donrsquot charge for its use Itrsquos small
The current version is about 150KB well within the memory budget of an Android phone
It requires no setup or administration There is no server no config file and no need for
a database administrator
Why SQLite
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 8: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/8.jpg)
Using the Internal Storage
Store private data on the device memory
You can save files directly on the devices internal storage
By default files saved to the internal storage are private to your application and other applications cannot access them (nor can the user)
When the user uninstalls your application these files are removed
Internal Storage
Call openFileOutput() with the name of the file and the operating mode This returns a FileOutputStream
Write to the file with write() Close the stream with close()
Write to files
Call openFileInput() and pass it the name of the file to read This returns a FileInputStream
Read bytes from the file with read() Then close the stream with close()
Read files
XML file resources
XML resources can mean resources in general that are defined in XML layout files styles arrays resxml XML files
In this section we will be dealing with resxml XML files
XML resources
Hello DatabaseSQLite Databases
A tiny yet powerful database engine created by Dr Richard Hipp in 2000
It is arguably the most widely deployed SQL database engine in the world
Besides Android SQLite can be found in the Apple iPhone Symbian phones Mozilla Firefox Skype PHP Adobe AIR Mac OS X Solaris and many other places
SQLite
Itrsquos free The authors have placed it in the public domain
and donrsquot charge for its use Itrsquos small
The current version is about 150KB well within the memory budget of an Android phone
It requires no setup or administration There is no server no config file and no need for
a database administrator
Why SQLite
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 9: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/9.jpg)
You can save files directly on the devices internal storage
By default files saved to the internal storage are private to your application and other applications cannot access them (nor can the user)
When the user uninstalls your application these files are removed
Internal Storage
Call openFileOutput() with the name of the file and the operating mode This returns a FileOutputStream
Write to the file with write() Close the stream with close()
Write to files
Call openFileInput() and pass it the name of the file to read This returns a FileInputStream
Read bytes from the file with read() Then close the stream with close()
Read files
XML file resources
XML resources can mean resources in general that are defined in XML layout files styles arrays resxml XML files
In this section we will be dealing with resxml XML files
XML resources
Hello DatabaseSQLite Databases
A tiny yet powerful database engine created by Dr Richard Hipp in 2000
It is arguably the most widely deployed SQL database engine in the world
Besides Android SQLite can be found in the Apple iPhone Symbian phones Mozilla Firefox Skype PHP Adobe AIR Mac OS X Solaris and many other places
SQLite
Itrsquos free The authors have placed it in the public domain
and donrsquot charge for its use Itrsquos small
The current version is about 150KB well within the memory budget of an Android phone
It requires no setup or administration There is no server no config file and no need for
a database administrator
Why SQLite
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 10: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/10.jpg)
Call openFileOutput() with the name of the file and the operating mode This returns a FileOutputStream
Write to the file with write() Close the stream with close()
Write to files
Call openFileInput() and pass it the name of the file to read This returns a FileInputStream
Read bytes from the file with read() Then close the stream with close()
Read files
XML file resources
XML resources can mean resources in general that are defined in XML layout files styles arrays resxml XML files
In this section we will be dealing with resxml XML files
XML resources
Hello DatabaseSQLite Databases
A tiny yet powerful database engine created by Dr Richard Hipp in 2000
It is arguably the most widely deployed SQL database engine in the world
Besides Android SQLite can be found in the Apple iPhone Symbian phones Mozilla Firefox Skype PHP Adobe AIR Mac OS X Solaris and many other places
SQLite
Itrsquos free The authors have placed it in the public domain
and donrsquot charge for its use Itrsquos small
The current version is about 150KB well within the memory budget of an Android phone
It requires no setup or administration There is no server no config file and no need for
a database administrator
Why SQLite
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 11: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/11.jpg)
Call openFileInput() and pass it the name of the file to read This returns a FileInputStream
Read bytes from the file with read() Then close the stream with close()
Read files
XML file resources
XML resources can mean resources in general that are defined in XML layout files styles arrays resxml XML files
In this section we will be dealing with resxml XML files
XML resources
Hello DatabaseSQLite Databases
A tiny yet powerful database engine created by Dr Richard Hipp in 2000
It is arguably the most widely deployed SQL database engine in the world
Besides Android SQLite can be found in the Apple iPhone Symbian phones Mozilla Firefox Skype PHP Adobe AIR Mac OS X Solaris and many other places
SQLite
Itrsquos free The authors have placed it in the public domain
and donrsquot charge for its use Itrsquos small
The current version is about 150KB well within the memory budget of an Android phone
It requires no setup or administration There is no server no config file and no need for
a database administrator
Why SQLite
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 12: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/12.jpg)
XML file resources
XML resources can mean resources in general that are defined in XML layout files styles arrays resxml XML files
In this section we will be dealing with resxml XML files
XML resources
Hello DatabaseSQLite Databases
A tiny yet powerful database engine created by Dr Richard Hipp in 2000
It is arguably the most widely deployed SQL database engine in the world
Besides Android SQLite can be found in the Apple iPhone Symbian phones Mozilla Firefox Skype PHP Adobe AIR Mac OS X Solaris and many other places
SQLite
Itrsquos free The authors have placed it in the public domain
and donrsquot charge for its use Itrsquos small
The current version is about 150KB well within the memory budget of an Android phone
It requires no setup or administration There is no server no config file and no need for
a database administrator
Why SQLite
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 13: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/13.jpg)
XML resources can mean resources in general that are defined in XML layout files styles arrays resxml XML files
In this section we will be dealing with resxml XML files
XML resources
Hello DatabaseSQLite Databases
A tiny yet powerful database engine created by Dr Richard Hipp in 2000
It is arguably the most widely deployed SQL database engine in the world
Besides Android SQLite can be found in the Apple iPhone Symbian phones Mozilla Firefox Skype PHP Adobe AIR Mac OS X Solaris and many other places
SQLite
Itrsquos free The authors have placed it in the public domain
and donrsquot charge for its use Itrsquos small
The current version is about 150KB well within the memory budget of an Android phone
It requires no setup or administration There is no server no config file and no need for
a database administrator
Why SQLite
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 14: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/14.jpg)
Hello DatabaseSQLite Databases
A tiny yet powerful database engine created by Dr Richard Hipp in 2000
It is arguably the most widely deployed SQL database engine in the world
Besides Android SQLite can be found in the Apple iPhone Symbian phones Mozilla Firefox Skype PHP Adobe AIR Mac OS X Solaris and many other places
SQLite
Itrsquos free The authors have placed it in the public domain
and donrsquot charge for its use Itrsquos small
The current version is about 150KB well within the memory budget of an Android phone
It requires no setup or administration There is no server no config file and no need for
a database administrator
Why SQLite
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 15: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/15.jpg)
A tiny yet powerful database engine created by Dr Richard Hipp in 2000
It is arguably the most widely deployed SQL database engine in the world
Besides Android SQLite can be found in the Apple iPhone Symbian phones Mozilla Firefox Skype PHP Adobe AIR Mac OS X Solaris and many other places
SQLite
Itrsquos free The authors have placed it in the public domain
and donrsquot charge for its use Itrsquos small
The current version is about 150KB well within the memory budget of an Android phone
It requires no setup or administration There is no server no config file and no need for
a database administrator
Why SQLite
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 16: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/16.jpg)
Itrsquos free The authors have placed it in the public domain
and donrsquot charge for its use Itrsquos small
The current version is about 150KB well within the memory budget of an Android phone
It requires no setup or administration There is no server no config file and no need for
a database administrator
Why SQLite
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 17: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/17.jpg)
Android stores the file datadatapackagenamedatabases
You can take that file move it around and even copy it to another system for example from your phone to your
workstation) and it will work fine You can use the adb command or the File
Explorer view in Eclipse to view move or delete it Window gt Show View gt Other gt Android gt File
Explorer)
A SQLite database is just a file
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 18: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/18.jpg)
Nothing here yet
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 19: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/19.jpg)
Goal Save time stamps
and string to a table
Display it
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 20: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/20.jpg)
Constants describing the database Constants interface
represent the database Using SQLiteOpenHelper
Driver Main program
Steps
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 21: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/21.jpg)
manages database creation and versions All you need to do is providea constructor and override two methods
DATABASE_VERSION is just a number we make up If this were a real program you would increasethe version number whenever you had to make significant changes to the database design (for example to add a new column)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 22: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/22.jpg)
close the database inside the finally block So even if an error occurs in the middle the database willstill be closed
Every time you run this program yoursquoll get a new event
Running a Query
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 23: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/23.jpg)
Data Binding
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 24: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/24.jpg)
Data Binding Allows you to connect your model (data) to
your view with just a few lines of code To demonstrate data binding wersquoll modify
the Events example to use a ListView that is bound to the result of a database query
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 25: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/25.jpg)
putting the ID time and title on one line with colons in between the fieldsadded a little padding and formatting to make it look nice
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-
![Page 26: Data Storage](https://reader035.vdocuments.us/reader035/viewer/2022062310/56815e6a550346895dcce641/html5/thumbnails/26.jpg)
need to change the layout for the activity itself in layoutmainxml
- Data Storage
- Reference
- Overview
- Shared Preferences
- SharedPreferences Class
- Slide 6
- Get SharedPreferences object
- To writeRead values
- Slide 9
- Using the Internal Storage
- Internal Storage
- Write to files
- Read files
- Slide 14
- Slide 15
- XML file resources
- XML resources
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Hello Database
- SQLite
- Why SQLite
- A SQLite database is just a file
- Slide 27
- Slide 28
- Steps
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Data Binding
- Slide 41
- Data Binding (2)
- Slide 43
- Slide 44
- Slide 45
- Slide 46
-