When to close database in ContentProvider

by Wah » Sun, 01 Mar 2009 16:10:59 GMT

Sponsored Links
 I am trying to write a ContentProvider which itself is based on a
SqlLite database. I am puzzled when I need to close the database
because ContentProvider has onCreate( ) function but not onDestroy( )

I downloaded the android source code tree, and found

It appears this class called "openDatabase" but never "close" on it:

    public boolean onCreate() {
        final Context con = getContext();
            mDb = mDbHelper.openDatabase(getContext(), DATABASE_NAME,
null, DB_V

mDb.close( ) is never called

If there is no onDestroy() from ContentProvider and we don't call close
( ) on databases, doesn't this lead to some kind of memory/resource


Other Threads

1. Problem in getting Image URI(s) from camera

Many people want this functionality, so do I. This is one of my
attempts. Can anyone guide me where am I going wrong...

I need to get the image URIs of all the images clicked by the camera
when it was running.
The basic logic I apply is this:

1] Before starting the camera, store a time stamp
                Date date = new Date();
                long milliDate = date.getTime();

2] Then I start the camera
                ComponentName camComp = new ComponentName
("com.android.camera", "com.android.camera.Camera");
                Intent takePic = new Intent();
                startActivityForResult(takePic, CAM_ACTIVITY);

3] And finally, when it returns, I try to find out all the image URIs
which were clicked during this time period i.e. time > milliDate

        if(requestCode == CAM_ACTIVITY){
                Cursor imgCursor = managedQuery
                                MediaStore.MediaColumns.DATE_ADDED + " > " + 
milliDate , null,

                if(imgCursor != null){
                        int _IDidx = imgCursor.getColumnIndex
                                String _ID = imgCursor.getString(_IDidx);
                                String content_URI =
MediaStore.Images.Media.EXTERNAL_CONTENT_URI + "/" + _ID;


Some thing is going wrong here and I get
android.database.CursorIndexOutOfBoundsException for the line String
_ID = imgCursor.getString(_IDidx);
Can anyone tell me where I'm going wrong !!


2. IMF Articles

"One of the major new features we are introducing in Android 1.5 is
our Input Method Framework (IMF), which allows developers on-screen
input methods such as software keyboards."

This is a concise article that I'm much looking forward to reading.
However, with this sentence corrected everything might come together
more easily. I also had a hard time with the other article so this is
a tough subject. So, when do I want to use the IMF?

- juan

3. Apps updating update

4. webview transition

5. How to create and open an SQLite database? (Based on NotePad tutorial)

6. Soft keypad not appearing for edit text-Urgent

7. how to get href value of a html file loaded on webview