【发布时间】:2015-04-13 21:08:08
【问题描述】:
我很确定 cursor 已被 IntentService 实例破坏,但我只是想确保没有内存泄漏。如果这是正常的做法。我正在查询我的自定义ContentProvider。
class MyService extends IntentService {
protected void onHandleIntent(Intent intent) {
Cursor cursor = getContentResolver().query(
MyContentProvider.CONTENT_URI, null, null, null, null);
if (cursor.getCount() == 0) {
return; // exit the method
} else {
cursor.close();
}
// some code...
}
}
【问题讨论】:
-
当然可以。每当
Cursor不再使用时,应立即将其关闭。 -
感谢您的回答。
标签: android android-contentprovider android-cursor android-intentservice