IndexOutOfBoundsException when I call stopManagingCursor in an OnItemSelectedListener

by Jeffrey Yasskin » Sun, 08 Mar 2009 08:50:37 GMT


Sponsored Links
 Activity.performStop() contains the following loop (around line 3394
in the 1.0 SDK release and at
 http://android.git.kernel.org/?p=platform/frameworks/base.git ;a=blob;f=core/java/android/app/Activity.java;h=4dc4b6a48b85f9caad4234b8e29fafdc9260840c;hb=HEAD#l3504):

            final int N = mManagedCursors.size();
            for (int i=0; i<N; i++) {
                ManagedCursor mc = mManagedCursors.get(i);
                if (!mc.mReleased) {
                    mc.mCursor.deactivate();
                    mc.mReleased = true;
                }
            }

In my app, mc.mCursor.deactivate() calls (indirectly)
SimpleCursorAdapter.notifyDataSetInvalidated(), which calls
(indirectly) AdapterView.fireOnSelected(), which calls my
OnItemSelectedListener, which calls stopManagingCursor(), which
reduces the size of mManagedCursors, which makes the ArrayList.get()
call throw on the next iteration.

I'm calling stopManagingCursor to avoid the crash described at <http://
groups.google.com/group/android-developers/browse_thread/thread/
f6fabc180e8b517a/c04691d80f1e9135?lnk=gst&#c04691d80f1e9135> (and a
few other posts you can find by searching this group for
"SQLiteClosable").

I suspect this is a bug in Activity.performStop, which shouldn't
assume mManagedCursors is constant through a call to a user-provided
callback. Until the Android developers can fix the bug, I'm looking
for a workaround. Should I just abandon managed cursors, which don't
seem to work well with CursorAdapters? Is there a good way to prevent
my OnItemSelectedListener from being called during performStop()? Any
other ideas?

Thanks,
Jeffrey
--~--~---------~--~----~------------~-------~--~----~



IndexOutOfBoundsException when I call stopManagingCursor in an OnItemSelectedListener

by Jeffrey Yasskin » Sun, 08 Mar 2009 10:40:05 GMT


 That's a reasonable idea, thanks. Right now, I'm calling changeCursor
(null) for each of my adapters in onDestroy(), but if I run into
trouble with leaking cursors before I can set them into an adapter
I'll try removing the listeners.

Filed at  http://code.google.com/p/android/issues/detail?id=2174. 




--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. published app not found by android market search

I have published an application. I have two beta users that have
utilized android market to download the application. They downloaded
and installed the app and it worked. This activity was a month or so
ago. The application does show up in my Developer Console today.

But when I search for the application, it is not found.

I search for the application exactly as the name appears in developer
console. I search for the application with just the name w/o the
version.

Thanks, John Brown

-- 

2. Dalvik execution mode

Hi all,
Can anyone brief the difference between fast and JIT dalvik execution
mode?
It is suggested that for android versions >= Froyo JIT should be
enabled but with JIT enabled in system.prop on accessing market
applications, browser, you tube phone is restarting everytime.

I'm using WITH_JIT =true, dalvik.vm.execution-mode = int:jit and
arm5te-vfp arch.

Please request to help me out in finding out the difference.

with regards,
Lavanya

-- 

3. Need some help please

4. Formatting a Preference Summary

5. a different list mechanism

6. finish doesn't call onDestroy on Android 2.2

7. AlphabetIndexer Letter 'Toast' Question