'StaleDataException'에 해당되는 글 1건

  1. 2012.12.12 android.database.StaleDataException

[로그]

12-12 11:59:09.025: E/AndroidRuntime(6603): FATAL EXCEPTION: main

12-12 11:59:09.025: E/AndroidRuntime(6603): android.database.StaleDataException: Attempted to access a cursor after it has been closed.

12-12 11:59:09.025: E/AndroidRuntime(6603):  at android.database.BulkCursorToCursorAdaptor.throwIfCursorIsClosed(BulkCursorToCursorAdaptor.java:75)

12-12 11:59:09.025: E/AndroidRuntime(6603):  at android.database.BulkCursorToCursorAdaptor.requery(BulkCursorToCursorAdaptor.java:144)

12-12 11:59:09.025: E/AndroidRuntime(6603):  at android.database.CursorWrapper.requery(CursorWrapper.java:186)

12-12 11:59:09.025: E/AndroidRuntime(6603):  at android.app.Activity.performRestart(Activity.java:4510)

12-12 11:59:09.025: E/AndroidRuntime(6603):  at android.app.ActivityThread.handleSleeping(ActivityThread.java:2952)

12-12 11:59:09.025: E/AndroidRuntime(6603):  at android.app.ActivityThread.access$2600(ActivityThread.java:127)

12-12 11:59:09.025: E/AndroidRuntime(6603):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1279)

12-12 11:59:09.025: E/AndroidRuntime(6603):  at android.os.Handler.dispatchMessage(Handler.java:99)

12-12 11:59:09.025: E/AndroidRuntime(6603):  at android.os.Looper.loop(Looper.java:137)

12-12 11:59:09.025: E/AndroidRuntime(6603):  at android.app.ActivityThread.main(ActivityThread.java:4511)

12-12 11:59:09.025: E/AndroidRuntime(6603):  at java.lang.reflect.Method.invokeNative(Native Method)

12-12 11:59:09.025: E/AndroidRuntime(6603):  at java.lang.reflect.Method.invoke(Method.java:511)

12-12 11:59:09.025: E/AndroidRuntime(6603):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:986)

12-12 11:59:09.025: E/AndroidRuntime(6603):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:753)

12-12 11:59:09.025: E/AndroidRuntime(6603):  at dalvik.system.NativeStart.main(Native Method)


[소스]

RingtoneManager ringtoneMgr = new RingtoneManager(mContext);

ringtoneMgr.setType(RingtoneManager.TYPE_ALARM);

Cursor alarmsCursor = ringtoneMgr.getCursor();

if(alarmsCursor != null){

    int alarmsCount = alarmsCursor.getCount();

    if(alarmsCount < 0){

        alarmsCursor.close();

        alarmsCursor = null;

        return;

    }


RingtoneManager의 getCursor 사용 후 Activity가 onResume 될때 아래의 Exception이 발생한다.

원인은 cursor를 close 하는데서 발생한다.

일반적인 Cursor는 당연히 close해야 하는 것이 정상이지만

RingtoneManager getCursor를 통해 가져온  Cursor 는 close 하지 말란다...


public Cursor getCursor ()

Added in API level 1

Returns a Cursor of all the ringtones available. The returned cursor will be the same cursor returned each time this method is called, so do not close() the cursor. The cursor can be deactivate() safely.

If RingtoneManager(Activity) was not used, the caller should manage the returned cursor through its activity's life cycle to prevent leaking the cursor. 



참고 : http://developer.android.com/reference/android/media/RingtoneManager.html#getCursor()











저작자 표시 비영리 변경 금지
신고
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by ocsoosoo

댓글을 달아 주세요

이전버튼 1 이전버튼

티스토리 툴바