Android 我是否必须关闭ContentResolver使用的游标?

Android 我是否必须关闭ContentResolver使用的游标?,android,android-contentresolver,android-cursor,Android,Android Contentresolver,Android Cursor,例如,给定以下代码: Cursor myCursor = context.getContentResolver() .query(MediaStore.CONTENT_URI, null, null, null, null);` 我必须关闭“我的光标”吗 谢谢 应始终以某种方式关闭游标,以避免内存泄漏。但是,如果要实现LoaderManager.LoaderCallbacks,则重写以下方法将为您关闭光标 @Override public void onLoaderReset(Load

例如,给定以下代码:

Cursor myCursor = context.getContentResolver()
    .query(MediaStore.CONTENT_URI, null, null, null, null);`
我必须关闭“我的光标”吗


谢谢

应始终以某种方式关闭游标,以避免内存泄漏。但是,如果要实现
LoaderManager.LoaderCallbacks
,则重写以下方法将为您关闭光标

@Override
public void onLoaderReset(Loader<Cursor> arg0) {
    cursorAdapter.swapCursor(null);
}
@覆盖
公共void onLoaderReset(加载程序arg0){
游标适配器.swapCursor(null);
}

是的,一旦您的工作完成,您需要始终关闭光标。@Grishu-如果您使用;,则不需要关闭光标)一般来说,是的,谢谢你的回复。然后,即使必须关闭CursorLoader使用过的游标?在最后一种情况下(CursorLoader),您也不需要但必须确保调用cursor.swap(null)来注销观察器。