一般用Cursor后, 就立即close()了,但是在用managedQuery的時候, 卻不能主動調用close()方法, 否則在Android 4.0+的系統上, 會發生崩潰
google的文檔是這么寫的
Warning: Do not call close() on a cursor obtained using this method, because the activity will do that for you at the appropriate time. However, if you call stopManagingCursor(Cursor) on a cursor from a managed query, the system will not automatically close the cursor and, in that case, you must call close().
也有人說用下面的方法可以避免這個問題
這個問題其實很簡單 估計大家在查詢數據庫的時候用的是這個函數
viedoCursor = context.managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoColumns,null, null, null);
只要換成這樣就可以了:
ContentResolver cr = context.getContentResolver();
viedoCursor = cr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoColumns,null, null, null);
我也是無意間發現有着兩種寫法的 然后試了一下問題就解決了
參考:http://stackoverflow.com/questions/9696868/unable-to-resume-activity-error