why after rotate ,will have error ?
FATAL EXCEPTION: main
Process: pom2.poly.com.trythemoviedbapi, PID: 798
java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteQuery: SELECT * FROM movie
at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:58)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:151)
at android.database.sqlite.SQLiteCursor.onMove(SQLiteCursor.java:123)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:236)
at android.database.CursorWrapper.moveToPosition(CursorWrapper.java:197)
at pom2.poly.com.trythemoviedbapi.MyRecyclerViewAdapter.onBindViewHolder(MyRecyclerViewAdapter.java:57)
at pom2.poly.com.trythemoviedbapi.MyRecyclerViewAdapter.onBindViewHolder(MyRecyclerViewAdapter.java:18)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5212)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5245)
|
it is because the program want to mcursor.moveToPosition(position);,However, the mcursor already is coled. But why the cursor closed? the cursor get from the cursor loder should be kepp alive.No, it is not keep alive, it jsut say after rotate,it will go to onLoadFinished directly.
after rotate,the onLoadFinished bennig call few time,so the myrecycleViewadapter.swapCursor(data); call too,
at here,may be ssome cursor is closed,so,have error,
soultion:
Method1.
Before use the cursor,check it it clise,, !mcursor.isClosed()
Method 2
why the onLoadFinished call few time? one reson is it will call by MainActivity and MainFragment itself,Total 10