Friday, January 13, 2012

[android-developers] Re: Managing Cursor provided to CursorAdapter via a FilterQueryProvider?

Nice :)

I did it slightly differently. I already had a standard top level
Activity all my Activities inherit from so in there i defined:

List<CursorAdapter> managedCursorAdaptors = new
ArrayList<CursorAdapter>();

and added the following methods:

protected void addManagedCursorAdapter(CursorAdapter adapter) {
managedCursorAdaptors.add(adapter);
}

protected void removeManagedCursorAdapter(CursorAdapter adapter) {
managedCursorAdaptors.remove(adapter);
}

protected void closeAllManagedCursorAdapters() {
Cursor cursor = null;
for(CursorAdapter adapter : managedCursorAdaptors) {
cursor = adapter.getCursor();
if(cursor != null) {
cursor.close();
}
}
}

I then in the onDestroy() called the closeAllManagedCursorAdapters.

Within my Activities whenever I created a CursorAdapter I don't keep a
reference to it as such I just call addManagedCursorAdapter(adapter)
and forget about it.

Seems to be working well enough and it's just set and forget.

Steve

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate