Hi!

How to best handle databases during the Activity life-cyle?

My example:

1. When I start the Activity I want to open the database so I create a
new dbAdapter and open it.

2. onCreate calls populateFields and data is read from the database I
just opened. The database remains opened because other functions in
the Activity needs the database.

3. the Activity gets Paused so I want to close my open database to
release resources : onPause --> dbAdapter.close()

4. the Activity gets Resumed so I need to open the database again:
onResume --> dbAdapter.open()

The problem: This will create two open instances of the database. When
the Activity starts the first time after onCreate has finished
onResume will be called (see: 
http://developer.android.com/intl/fr/images/activity_lifecycle.png).
What's best practise to solve this?

This error of handling databases is also present in the Notepad
Tutorial.

//Anders

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to