在使用数据库操作查询数据后,如果是在Activity里面处理,那么很可能就会用到startManagingCursor()方法,在这里讲一下它的作用和使用注意事项.
调用这个方法,就是将获得的Cursor对象交与Activity 来管理,这样Cursor对象的生命周期便能与当前的Activity自动同步,省去了自己管理Cursor。
This method allows the activity to take care of managing the given Cursor
's lifecycle for you based on the activity's lifecycle. That is, when the activity is stopped it will automatically call Cursor.deactivate
on the given Cursor, and when it is later restarted it will call Cursor.requery
for you. When the activity is destroyed, all managed Cursors will be closed automatically. If you are targeting android.os.Build.VERSION_CODES.HONEYCOMB
or later, consider instead using LoaderManager
instead, available via getLoaderManager()
.
Warning: Do not call Cursor.close()
on cursor obtained from managedQuery
, because the activity will do that for you at the appropriate time. However, if you call stopManagingCursor
on a cursor from a managed query, the system will not automatically close the cursor and, in that case, you must call Cursor.close()
.