Q:

ListView - SimpleCursorAdapter - @android:id/empty

tI've a ListActivity. The layout of the ListActivity is
<ListView android:id="@android:id/list"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:layout_weight="1"
           android:drawSelectorOnTop="false"
           />

<TextView android:id="@android:id/empty"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:text="No elements found"
           android:gravity="center"  
           />

The ListActivity is related to a CursorAdapter.
When a user selects an item of the list, I start another activity to show the details of the item selected:
Intent intent = new Intent(MyListActivity.this, DetailActivity.class);
startActivity(intent);

Everything works fine, except when the user selects an item of the list. Before starting the "detail activity", the "No elements found" message of the textview with "@android:id/empty" id is shown.
This is happening because I close the cursor in the onPause method. But I think that I must close it, because I'm leaving the current activity.
@Override
protected void onPause()
{
    super.onPause();            

    if (this.cursor != null)
        this.cursor.close();

    this.db.close();        
}

What could I do if I don't want to see the textview with "@android:id/empty" when I'm leaving the current activity??
Thanks

A:

Let the system manage it for you.
getActivity().startManagingCursor(yourCursor);

Call that code (with the proper cursor variable name in there) right after you call the cursor and the system will take care of managing the cursor for you, closing it when it deems it is no longer needed.
Your other option is to move that code to the onStop method which is called when the activity is no longer visible to the user.

