我有:Accounts.java
public class Accounts{
private SQLiteDatabase dbConfig;
public Cursor list(Context context, String db, String where, String order) {
DBHelper dbHelper = new DBHelper(context, db);
dbConfig = dbHelper.getReadableDatabase();
Cursor c = dbConfig.query("accounts", new String[]{ "iId","sName"}, where, null, null, null, order);
return c;
}
}
和:MainActivity.java
Accounts account = new Accounts();
Cursor cursor = account.list(getApplicationContext(), globalDB, null, null);
while (cursor.moveToNext()) {
int id = cursor.getInt(0);
String name = cursor.getString(1);
}
cursor.close();
运行我的应用程序,我收到一些 logcat 消息,例如:
close() was never explicitly called on database...
预防它的最佳方法是什么?如何关闭从其他类返回的光标?谢谢