working with databases in android

46
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

Upload: stephen-gilmore

Post on 28-May-2015

907 views

Category:

Education


4 download

DESCRIPTION

A description of a TODO-note application which uses the Android database. The application is due to Lars Vogel.

TRANSCRIPT

Page 1: Working with databases in Android

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

Page 2: Working with databases in Android

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

Page 3: Working with databases in Android

Lars Vogel example: TODOs

shot 2011-10-26 at 22.05.05.png

Stephen Gilmore Software Engineering Large Practical

Page 4: Working with databases in Android

A database example

shot 2011-10-26 at 22.05.57.png

Stephen Gilmore Software Engineering Large Practical

Page 5: Working with databases in Android

TodoDatabaseAdapter

shot 2011-10-26 at 22.05.57.png

Stephen Gilmore Software Engineering Large Practical

Page 6: Working with databases in Android

TodoDatabaseHelper (onCreate())

shot 2011-10-26 at 22.10.01.png

Stephen Gilmore Software Engineering Large Practical

Page 7: Working with databases in Android

TodoDatabaseHelper (onUpgrade())

shot 2011-10-26 at 22.10.02.png

Stephen Gilmore Software Engineering Large Practical

Page 8: Working with databases in Android

TodoDatabaseAdapter (open(), close())

shot 2011-10-26 at 22.12.06.png

Stephen Gilmore Software Engineering Large Practical

Page 9: Working with databases in Android

The create, update, and delete methods

shot 2011-10-26 at 22.12.29.png

Stephen Gilmore Software Engineering Large Practical

Page 10: Working with databases in Android

The insert() method

shot 2011-10-27 at 19.42.45.png

Stephen Gilmore Software Engineering Large Practical

Page 11: Working with databases in Android

The update() method

shot 2011-10-27 at 19.43.02.png

Stephen Gilmore Software Engineering Large Practical

Page 12: Working with databases in Android

The delete() method

shot 2011-10-27 at 19.43.10.png

Stephen Gilmore Software Engineering Large Practical

Page 13: Working with databases in Android

Fetch data

shot 2011-10-26 at 22.13.10.png

Stephen Gilmore Software Engineering Large Practical

Page 14: Working with databases in Android

Create content values

shot 2011-10-26 at 22.13.10.png

Stephen Gilmore Software Engineering Large Practical

Page 15: Working with databases in Android

Resources

shot 2011-10-26 at 15.45.00.png

Stephen Gilmore Software Engineering Large Practical

Page 16: Working with databases in Android

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

Page 17: Working with databases in Android

Running the TODOs application

shot 2011-10-26 at 23.14.13.pngStephen Gilmore Software Engineering Large Practical

Page 18: Working with databases in Android

Editing a TODO item

shot 2011-10-26 at 23.14.20.pngStephen Gilmore Software Engineering Large Practical

Page 19: Working with databases in Android

Setting category to “Urgent”

shot 2011-10-26 at 23.16.00.pngStephen Gilmore Software Engineering Large Practical

Page 20: Working with databases in Android

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

Page 21: Working with databases in Android

TodoDetails (imports)

shot 2011-10-27 at 16.14.20.png

Stephen Gilmore Software Engineering Large Practical

Page 22: Working with databases in Android

TodoDetails (onCreate)

shot 2011-10-27 at 16.14.31.png

Stephen Gilmore Software Engineering Large Practical

Page 23: Working with databases in Android

Graphical layout of todo edit.xml

shot 2011-10-27 at 16.32.52.png

Stephen Gilmore Software Engineering Large Practical

Page 24: Working with databases in Android

Text of todo edit.xml

shot 2011-10-27 at 16.32.48.png

Stephen Gilmore Software Engineering Large Practical

Page 25: Working with databases in Android

Outline of todo edit.xml

shot 2011-10-27 at 16.32.48.png

Stephen Gilmore Software Engineering Large Practical

Page 26: Working with databases in Android

TodoDetails (populateFields)

shot 2011-10-27 at 16.14.38.png

Stephen Gilmore Software Engineering Large Practical

Page 27: Working with databases in Android

Save state, onPause, onResume

shot 2011-10-27 at 16.14.48.png

Stephen Gilmore Software Engineering Large Practical

Page 28: Working with databases in Android

Save state

shot 2011-10-27 at 16.14.56.png

Stephen Gilmore Software Engineering Large Practical

Page 29: Working with databases in Android

TodosOverview (onCreate)

shot 2011-10-27 at 16.15.04.png

Stephen Gilmore Software Engineering Large Practical

Page 30: Working with databases in Android

Options menu, item selected

shot 2011-10-27 at 16.15.10.png

Stephen Gilmore Software Engineering Large Practical

Page 31: Working with databases in Android

Options item selected

shot 2011-10-27 at 16.15.22.png

Stephen Gilmore Software Engineering Large Practical

Page 32: Working with databases in Android

Accessing the insert menu

shot 2011-10-27 at 20.16.16.png

Stephen Gilmore Software Engineering Large Practical

Page 33: Working with databases in Android

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

Page 34: Working with databases in Android

Dalvik Debug Monitor Server (DDMS)

shot 2011-10-26 at 23.21.38.png

Stephen Gilmore Software Engineering Large Practical

Page 35: Working with databases in Android

File explorer in DDMS

shot 2011-10-26 at 23.21.38.png

Stephen Gilmore Software Engineering Large Practical

Page 36: Working with databases in Android

/data/data/de.vogella.android.todos/...

shot 2011-10-26 at 15.59.41.png

Stephen Gilmore Software Engineering Large Practical

Page 37: Working with databases in Android

Pulling a file from the device

shot 2011-10-26 at 15.59.41.png

Stephen Gilmore Software Engineering Large Practical

Page 38: Working with databases in Android

Pulling a file from the device

shot 2011-10-26 at 15.59.40.png

Stephen Gilmore Software Engineering Large Practical

Page 39: Working with databases in Android

Get the device file

shot 2011-10-26 at 16.00.40.png

Stephen Gilmore Software Engineering Large Practical

Page 40: Working with databases in Android

Inspecting the file with sqlite3

shot 2011-10-26 at 16.05.38.png

Stephen Gilmore Software Engineering Large Practical

Page 41: Working with databases in Android

Inspecting the file with sqlite3 on DiCE

shot 2011-10-26 at 16.11.58.png

Stephen Gilmore Software Engineering Large Practical

Page 42: Working with databases in Android

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

Page 43: Working with databases in Android

Using LogCat

As usual, the effect of Java exceptions and other problems willappear in the LogCat view.

Stephen Gilmore Software Engineering Large Practical

Page 44: Working with databases in Android

Debugs and errors displayed in LogCat

shot 2011-10-26 at 23.22.45.png

Stephen Gilmore Software Engineering Large Practical

Page 45: Working with databases in Android

Can filter messages displayed in LogCat

shot 2011-10-27 at 15.34.51.png

Stephen Gilmore Software Engineering Large Practical

Page 46: Working with databases in Android

Can use view menu to export messages

shot 2011-10-27 at 15.40.30.png

Stephen Gilmore Software Engineering Large Practical