我在while循環中使用遊標在我的數據庫上執行多個查詢,所以每次Content Resolver返回新的遊標對象實例。我不確定有道循環的每次迭代過程中,我應該重新使用遊標:光標變量重用
關閉一次,在每次迭代結束執行
Cursor c; try { while(condition) { c = Context.getContentResolver().query(...); // fetching values } } finally { if (c != null) { c.close() } }
關閉其所有操作之後,
Cursor c; try { while(condition) { c = Context.getContentResolver().query(...); // fetching values if (c != null) { c.close() } } } finally { if (c != null) { c.close() } }
內創建新的遊標變量while循環
while(condition) { Cursor c = Context.getContentResolver().query(...); try { // fetching values } finally { if (c != null) { c.close() } } }
?
而且看起來最乾淨以及imo。 – tomwyr