REDGUY: ten kurzor je jediný, který se používá a na jednom místě.
Tu onPause() ve FragmentList jsem tedy naimplementoval takto:
public void onPause() {
if (!this.c.isClosed()) {
this.c.close();
}
this.model.close();
super.onPause();
}
Při překlápění obrazovky mi to zatím tu výjimku nevyhodilo, ale bohužel to teď náhodně shazuje aplikaci, ať už při zastavení tlačítkem Home nebo naopak znovu vyvolání. Ale taky ne pokaždé, prostě náhodně. Ta výjimka je:
06-04 18:10:32.493: E/AndroidRuntime(2284): FATAL EXCEPTION: main
06-04 18:10:32.493: E/AndroidRuntime(2284): java.lang.RuntimeException: Unable to pause activity {cz.test/cz.test.activity.MainActivity}: android.database.StaleDataException: Access closed cursor
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3348)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3305)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3288)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.app.ActivityThread.access$2500(ActivityThread.java:125)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2040)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.os.Handler.dispatchMessage(Handler.java:99)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.os.Looper.loop(Looper.java:123)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-04 18:10:32.493: E/AndroidRuntime(2284): at java.lang.reflect.Method.invokeNative(Native Method)
06-04 18:10:32.493: E/AndroidRuntime(2284): at java.lang.reflect.Method.invoke(Method.java:521)
06-04 18:10:32.493: E/AndroidRuntime(2284): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-04 18:10:32.493: E/AndroidRuntime(2284): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-04 18:10:32.493: E/AndroidRuntime(2284): at dalvik.system.NativeStart.main(Native Method)
06-04 18:10:32.493: E/AndroidRuntime(2284): Caused by: android.database.StaleDataException: Access closed cursor
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:217)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:99)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.support.v4.widget.CursorAdapter.getItemId(CursorAdapter.java:226)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.widget.AbsListView.onSaveInstanceState(AbsListView.java:885)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.widget.ListView.onSaveInstanceState(ListView.java:3625)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.view.View.dispatchSaveInstanceState(View.java:6068)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.view.ViewGroup.dispatchFreezeSelfOnly(ViewGroup.java:1197)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.widget.AdapterView.dispatchSaveInstanceState(AdapterView.java:759)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1184)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.view.View.saveHierarchyState(View.java:6051)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.support.v4.app.FragmentManagerImpl.saveFragmentViewState(FragmentManager.java:1574)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1594)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1655)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:527)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.app.Activity.performSaveInstanceState(Activity.java:1036)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1180)
06-04 18:10:32.493: E/AndroidRuntime(2284): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3330)
06-04 18:10:32.493: E/AndroidRuntime(2284): ... 12 more