ExpandableListView, CursorTreeAdapter and cursor management
Trying to use ExpandableListView and CursorTreeAdapter. Here th quote from Android manual:
protected abstract Cursor getChildrenCursor (Cursor groupCursor) ... It is your responsibility to manage this Cursor through the Activity lifecycle. In some situations, the adapter will deactivate the Cursor on its own, but this will not always be the case, so please ensure the Cursor is properly managed.
Ok, I find with Google some examples and wrote the following code:
@Override
protected Cursor getChildrenCursor( Cursor groupCursor ) {
int groupID = groupCursor.getInt( groupIDColumn );
Cursor c = dbAdapter.getHostsCursor( "where expression", groupID );
startManagingCursor( c );
return c;
}
This code works, but ExpandableListView requests new cursor on every click on a group to expand it. New cursors are created and added to Activity's list of managed cursors.
But what happens t开发者_开发技巧o the old cursors? Where I can close old, unused cursor, call stopManagingCursor(), if I'm responsible to manage cursors according to Google manual? If someone will be click to expand and collapse groups, how quickly app will crashed with stack overflow or another leak of system resources?
Please point me to the right direction.
Consider these two alternatives:
getChildrenCursor()
returns a cursor that will not live long.The UI is updated and then the cursor is disposed.
Each Group has a cursor.
There is no room for optimization.
choice 1 is probably true
精彩评论