私はこのメソッドを使って、リストビューにsqliteデータベースのデータを入力します。これは、アプリケーションが起動されたときに期待どおりに動作: startManagingCursorを2回呼び出すとデータがなくなります
private void populateListView() {
Cursor showsCursor = mDbHelper.fetchAllSummaries();
startManagingCursor(showsCursor);
// Create an array to specify the fields we want to display in the list
String[] from = new String[]{DbAdapter.SUMMARY_TITLE, DbAdapter.SUMMARY_DATE, DbAdapter.SUMMARY_SUMMARY};
// and an array of the fields we want to bind those fields to
int[] to = new int[]{R.id.showtitle, R.id.showdate, R.id.showsummary};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter shows =
new SimpleCursorAdapter(this, R.layout.custom_row_view, showsCursor, from, to);
setListAdapter(shows);
}
は、その後私も更新されたデータとリストビューを埋めるためにもう一度()データベースを更新し、populateListViewを呼び出し、最新の情報に更新]メニュー項目を持っています。それも
のように表示されます。
しかし、正確にはありません!リストビュー項目の1つをクリックして別のアクティビティを開始し、戻るボタンを使用して戻ると、リストビューが空になるためです。 populateListView()を再度呼び出すと再作成されますが、別のアクティビティから返されたときに再び空になります。
私がstartManagingCursor()を省略すると、完全に動作することがわかりました。
したがって、startManagingCursor()を2回呼び出すと、予期しない副作用が発生するようです。なぜこれが起こっているのですか?どのように解決できますか?
startManagingCursor()を呼び出すのは間違っていますか?それは、onCreate()メソッドにあるべきですか?そして、実際にstopManagingCursor()を一度呼び出す必要がありますか?