大家好,又见面了,我是全栈君。
在使用数据库操作查询数据后,如果是在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()
.
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/121427.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...