working with databases in android
DESCRIPTION
A description of a TODO-note application which uses the Android database. The application is due to Lars Vogel.TRANSCRIPT
Software Engineering Large Practical
Working with databases in Android
Stephen Gilmore
School of Informatics, University of Edinburgh
October 17th, 2012
Stephen Gilmore Software Engineering Large Practical
A database example
In this lecture we will look at an example Android applicationwhich creates a database of TODO notes, with reminders of thingswhich need to be done, and descriptions of these.
The application is due to Lars Vogel (http://www.vogella.com).
Stephen Gilmore Software Engineering Large Practical
Lars Vogel example: TODOs
shot 2011-10-26 at 22.05.05.png
Stephen Gilmore Software Engineering Large Practical
A database example
shot 2011-10-26 at 22.05.57.png
Stephen Gilmore Software Engineering Large Practical
TodoDatabaseAdapter
shot 2011-10-26 at 22.05.57.png
Stephen Gilmore Software Engineering Large Practical
TodoDatabaseHelper (onCreate())
shot 2011-10-26 at 22.10.01.png
Stephen Gilmore Software Engineering Large Practical
TodoDatabaseHelper (onUpgrade())
shot 2011-10-26 at 22.10.02.png
Stephen Gilmore Software Engineering Large Practical
TodoDatabaseAdapter (open(), close())
shot 2011-10-26 at 22.12.06.png
Stephen Gilmore Software Engineering Large Practical
The create, update, and delete methods
shot 2011-10-26 at 22.12.29.png
Stephen Gilmore Software Engineering Large Practical
The insert() method
shot 2011-10-27 at 19.42.45.png
Stephen Gilmore Software Engineering Large Practical
The update() method
shot 2011-10-27 at 19.43.02.png
Stephen Gilmore Software Engineering Large Practical
The delete() method
shot 2011-10-27 at 19.43.10.png
Stephen Gilmore Software Engineering Large Practical
Fetch data
shot 2011-10-26 at 22.13.10.png
Stephen Gilmore Software Engineering Large Practical
Create content values
shot 2011-10-26 at 22.13.10.png
Stephen Gilmore Software Engineering Large Practical
Resources
shot 2011-10-26 at 15.45.00.png
Stephen Gilmore Software Engineering Large Practical
Running the application
When we run the application we are able to create a TODO note,and set its category to Urgent or Reminder.
Stephen Gilmore Software Engineering Large Practical
Running the TODOs application
shot 2011-10-26 at 23.14.13.pngStephen Gilmore Software Engineering Large Practical
Editing a TODO item
shot 2011-10-26 at 23.14.20.pngStephen Gilmore Software Engineering Large Practical
Setting category to “Urgent”
shot 2011-10-26 at 23.16.00.pngStephen Gilmore Software Engineering Large Practical
TODOs application code
We look at the application code to see how the Java code interactswith the XML layout and see how the database state is managed.
Stephen Gilmore Software Engineering Large Practical
TodoDetails (imports)
shot 2011-10-27 at 16.14.20.png
Stephen Gilmore Software Engineering Large Practical
TodoDetails (onCreate)
shot 2011-10-27 at 16.14.31.png
Stephen Gilmore Software Engineering Large Practical
Graphical layout of todo edit.xml
shot 2011-10-27 at 16.32.52.png
Stephen Gilmore Software Engineering Large Practical
Text of todo edit.xml
shot 2011-10-27 at 16.32.48.png
Stephen Gilmore Software Engineering Large Practical
Outline of todo edit.xml
shot 2011-10-27 at 16.32.48.png
Stephen Gilmore Software Engineering Large Practical
TodoDetails (populateFields)
shot 2011-10-27 at 16.14.38.png
Stephen Gilmore Software Engineering Large Practical
Save state, onPause, onResume
shot 2011-10-27 at 16.14.48.png
Stephen Gilmore Software Engineering Large Practical
Save state
shot 2011-10-27 at 16.14.56.png
Stephen Gilmore Software Engineering Large Practical
TodosOverview (onCreate)
shot 2011-10-27 at 16.15.04.png
Stephen Gilmore Software Engineering Large Practical
Options menu, item selected
shot 2011-10-27 at 16.15.10.png
Stephen Gilmore Software Engineering Large Practical
Options item selected
shot 2011-10-27 at 16.15.22.png
Stephen Gilmore Software Engineering Large Practical
Accessing the insert menu
shot 2011-10-27 at 20.16.16.png
Stephen Gilmore Software Engineering Large Practical
Inspecting the database
During development we might have bugs in our code which causeproblems with the database. In this case we would like to be ableto see the content of the database and check that it is as weexpect. We can use the Dalvik Debug Monitor Server (DDMS) todo this and we can also inspect the database using other tools forprocessing SQLlite databases.
Stephen Gilmore Software Engineering Large Practical
Dalvik Debug Monitor Server (DDMS)
shot 2011-10-26 at 23.21.38.png
Stephen Gilmore Software Engineering Large Practical
File explorer in DDMS
shot 2011-10-26 at 23.21.38.png
Stephen Gilmore Software Engineering Large Practical
/data/data/de.vogella.android.todos/...
shot 2011-10-26 at 15.59.41.png
Stephen Gilmore Software Engineering Large Practical
Pulling a file from the device
shot 2011-10-26 at 15.59.41.png
Stephen Gilmore Software Engineering Large Practical
Pulling a file from the device
shot 2011-10-26 at 15.59.40.png
Stephen Gilmore Software Engineering Large Practical
Get the device file
shot 2011-10-26 at 16.00.40.png
Stephen Gilmore Software Engineering Large Practical
Inspecting the file with sqlite3
shot 2011-10-26 at 16.05.38.png
Stephen Gilmore Software Engineering Large Practical
Inspecting the file with sqlite3 on DiCE
shot 2011-10-26 at 16.11.58.png
Stephen Gilmore Software Engineering Large Practical
Other tools for inspecting the database
Numerous browsers exist for SQLite databases.
I The CellObject SQLite & XML Browser is an Eclipseplug-in tool built on top of Dalvik Debug Monitor Server(DDMS), intended for Android application developers. It isavailable from http://cellobject.net/
I SQLite Manager is an add-on for Firefox which allows usersto browse SQLite databases using the Firefox browser. It isavailable from https://addons.mozilla.org/en-US/
firefox/addon/sqlite-manager/
I SQLite Database Browser allows users to create, design andedit database files compatible with SQLite using a familiarspreadsheet-like interface. It is available fromhttp://sqlitebrowser.sourceforge.net/
Stephen Gilmore Software Engineering Large Practical
Using LogCat
As usual, the effect of Java exceptions and other problems willappear in the LogCat view.
Stephen Gilmore Software Engineering Large Practical
Debugs and errors displayed in LogCat
shot 2011-10-26 at 23.22.45.png
Stephen Gilmore Software Engineering Large Practical
Can filter messages displayed in LogCat
shot 2011-10-27 at 15.34.51.png
Stephen Gilmore Software Engineering Large Practical
Can use view menu to export messages
shot 2011-10-27 at 15.40.30.png
Stephen Gilmore Software Engineering Large Practical