我延伸了上一个问题,我解决了这个问题但是我遇到了类似的新错误。
我有以下活动
public class ActivityMatchesList extends FragmentActivity implements LoaderManager.LoaderCallbacks<Cursor> {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView lvLive = (ListView)findViewById(R.id.matchListList);
lvLive.setOnItemClickListener(OnItemClickListenerLive);
getSupportLoaderManager().initLoader(1, null, this);
getSupportLoaderManager().initLoader(2, null, this);
getSupportLoaderManager().initLoader(3, null, this);
}
private OnItemClickListener OnItemClickListenerLive = new OnItemClickListener(){
Intent i = new Intent(ActivityMatchesList.this, ActivityEvents.class);
finish();
startActivity(i);
}
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) { //FIXME: add switch for 3 loader
switch (id){
case 1:
CursorLoader cursorLoaderLive = new CursorLoader(this, uri1,null,null,null,null);
return cursorLoaderLive;
case 2:
CursorLoader cursorLoaderRankingLeague = new CursorLoader(this, uri1,null,null,null,null);
return cursorLoaderRankingLeague;
case 3:
CursorLoader cursorLoaderRankingLive = new CursorLoader(this, uri1,null,null,null,null);
return cursorLoaderRankingLive;
default:
return null;
}
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
switch (loader.getId()){
case 1:
Adapter1.swapCursor(cursor);
break;
case 2:
Adapter2.swapCursor(cursor);
break;
case 3:
Adapter3.swapCursor(cursor);
break;
}
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
switch (loader.getId()){
case 1:
Adapter1.swapCursor(null);
break;
case 2:
Adapter2.swapCursor(null);
break;
case 3:
Adapter3.swapCursor(null);
break;
}
}
}
使用OnItemClickListener我完成()这个活动并开始一个新的,当我完成新的回到这个时候我有以下错误
11-30 09:35:01.839: INFO/dalvikvm(321): Uncaught exception thrown by finalizer (will be discarded):
11-30 09:35:01.848: INFO/dalvikvm(321): Ljava/lang/IllegalStateException;: Finalizing cursor android.database.sqlite.SQLiteCursor@43c6ab00 on MAIN_TABLE that has not been deactivated or closed
11-30 09:35:01.848: INFO/dalvikvm(321): at android.database.sqlite.SQLiteCursor.finalize(SQLiteCursor.java:596)
11-30 09:35:01.848: INFO/dalvikvm(321): at dalvik.system.NativeStart.run(Native Method)
我无法找到原因,有人可以帮助我吗?
编辑:如果我只使用1个加载器,问题仍然存在。似乎在活动结束时装载机有时候不会关闭光标,为什么?
答案 0 :(得分:0)
为什么在开始新活动之前在此活动中调用finish()
? Android处理活动生命周期。如果是因为您不希望在下一个活动结束时返回此活动,请考虑noHistory。
您发布的错误意味着应该已经关闭了一个打开的游标。如果您在完成新活动时看到错误,它似乎向我表明错误是在新活动中,而不是在此活动中。在完成新活动之前,您可能需要致电Cursor.close()(可能在onPause()
或onDestroy()
)。
我对您之前提问的回答也可能有用:https://stackoverflow.com/a/8857179/399105