使用DrawerLayout强制使用LoaderManager的支持库?

时间:2015-01-16 19:51:44

标签: android android-support-library android-loadermanager

我的应用程序有一些活动,没有片段,DrawerLayout,所有活动都使用Loaders通过ContentProvider访问数据库。我在我的两个活动中(而不是在其他活动中)​​遇到的问题类似于onCreateLoader not called when orientation changes中描述的问题: 当更改设备的方向时,getLoaderManager()。onResume()中的initLoader()被调用,但这导致仅在两个方向之一(初始方向)中回调onLoadFinished()。重复改变方向总是有同样的效果。

onCreateLoader not called when orientation changes中问题的不同之处在于我没有在支持库中使用Fragments with FragmentActivity。但我还要使用DrawerLayout的支持库。

使用支持库的任何部分是否始终使用支持库中的LoaderManager.LoaderCallbacks强制执行? 如果是,我在哪里可以找到这些信息?

使用LoaderManager.enableDebugLogging(true)我得到以下日志: 第一次加载活动:

initLoader in LoaderManager{4221a5a0 in RepairInfo{422051c0}}: args=null
  Starting: LoaderInfo{4221aab8 #12 : CursorLoader{4221abc0}}
  Created new loader LoaderInfo{4221aab8 #12 : CursorLoader{4221abc0}}
restartLoader in LoaderManager{4221a5a0 in RepairInfo{422051c0}}: args=Bundle[{PartTypeDbId=1, BikeDbId=23}]
  Starting: LoaderInfo{4221c128 #11 : CursorLoader{4221cee8}}
onLoadComplete: LoaderInfo{4221aab8 #12 : CursorLoader{4221abc0}}
  onLoadFinished in CursorLoader{4221abc0 id=12}: CursorWrapperInner{42224a58}
onLoadComplete: LoaderInfo{4221c128 #11 : CursorLoader{4221cee8}}
  onLoadFinished in CursorLoader{4221cee8 id=11}: CursorWrapperInner{42224b50}
Stopping in LoaderManager{4219c730 in BikeDescription{41e4f930}}
  Stopping: LoaderInfo{4219cfc0 #3 : CursorLoader{4219dc90}}
  Stopping: LoaderInfo{421a1b88 #2 : CursorLoader{421a2b50}}

更改设备的方向我收到此日志 - 没有任何onLoadComplete,因此没有显示数据库数据:

Retaining in LoaderManager{4221a5a0 in RepairInfo{422051c0}}
      Retaining: LoaderInfo{4221aab8 #12 : CursorLoader{4221abc0}}
      Retaining: LoaderInfo{4221c128 #11 : CursorLoader{4221cee8}}
    Destroying Inactive in LoaderManager{4221a5a0 in RepairInfo{422051c0}}
    Finished Retaining in LoaderManager{4221a5a0 in RepairInfo{4223a8d8}}
      Finished Retaining: LoaderInfo{4221aab8 #12 : CursorLoader{4221abc0}}
      Stopping: LoaderInfo{4221aab8 #12 : CursorLoader{4221abc0}}
      Finished Retaining: LoaderInfo{4221c128 #11 : CursorLoader{4221cee8}}
      Stopping: LoaderInfo{4221c128 #11 : CursorLoader{4221cee8}}
    initLoader in LoaderManager{4221a5a0 in RepairInfo{4223a8d8}}: args=null
      Re-using existing loader LoaderInfo{4221aab8 #12 : CursorLoader{4221abc0}}
    restartLoader in LoaderManager{4221a5a0 in RepairInfo{4223a8d8}}: args=Bundle[{PartTypeDbId=1, BikeDbId=23}]
      Making last loader inactive: LoaderInfo{4221c128 #11 : CursorLoader{4221cee8}}
    restartLoader in LoaderManager{4221a5a0 in RepairInfo{4223a8d8}}: args=Bundle[{PartTypeDbId=1, BikeDbId=23}]
      Current loader is stopped; replacing
      Destroying: LoaderInfo{4224ffe8 #11 : CursorLoader{422501e0}}    

将设备的方向更改回其初始方向会产生警告,但具有onLoadComplete并显示所有数据,如第一次调用:

Retaining in LoaderManager{4221a5a0 in RepairInfo{4223a8d8}}
Called doRetain when not started: LoaderManager{4221a5a0 in RepairInfo{4223a8d8}}
java.lang.RuntimeException: here
    at android.app.LoaderManagerImpl.doRetain(LoaderManager.java:795)
    at android.app.Activity.performStop(Activity.java:5359)
    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3480)
    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3539)
    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3739)
    at android.app.ActivityThread.access$900(ActivityThread.java:144)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1211)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5146)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
    at dalvik.system.NativeStart.main(Native Method)
Destroying Active in LoaderManager{4221a5a0 in RepairInfo{4223a8d8}}
  Destroying: LoaderInfo{4221aab8 #12 : CursorLoader{4221abc0}}
  Reseting: LoaderInfo{4221aab8 #12 : CursorLoader{4221abc0}}
  Destroying: LoaderInfo{42262f28 #11 : CursorLoader{42263120}}
Destroying Inactive in LoaderManager{4221a5a0 in RepairInfo{4223a8d8}}
  Destroying: LoaderInfo{4221c128 #11 : CursorLoader{4221cee8}}
Destroying Active in LoaderManager{4221a5a0 in RepairInfo{4223a8d8}}
Destroying Inactive in LoaderManager{4221a5a0 in RepairInfo{4223a8d8}}
initLoader in LoaderManager{42280020 in RepairInfo{4226cf08}}: args=null
  Starting: LoaderInfo{42280538 #12 : CursorLoader{42280580}}
  Created new loader LoaderInfo{42280538 #12 : CursorLoader{42280580}}
restartLoader in LoaderManager{42280020 in RepairInfo{4226cf08}}: args=Bundle[{PartTypeDbId=1, BikeDbId=23}]
  Starting: LoaderInfo{42281d30 #11 : CursorLoader{42281fe8}}
onLoadComplete: LoaderInfo{42281d30 #11 : CursorLoader{42281fe8}}
  onLoadFinished in CursorLoader{42281fe8 id=11}: CursorWrapperInner{42284950}
onLoadComplete: LoaderInfo{42280538 #12 : CursorLoader{42280580}}
  onLoadFinished in CursorLoader{42280580 id=12}: CursorWrapperInner{42284a48}
restartLoader in LoaderManager{42280020 in RepairInfo{4226cf08}}: args=Bundle[{PartTypeDbId=1, BikeDbId=23}]
  Making last loader inactive: LoaderInfo{42281d30 #11 : CursorLoader{42281fe8}}
  Starting: LoaderInfo{4229d218 #11 : CursorLoader{4229d410}}
onLoadComplete: LoaderInfo{4229d218 #11 : CursorLoader{4229d410}}
  onLoadFinished in CursorLoader{4229d410 id=11}: CursorWrapperInner{4229ecc0}
  Destroying: LoaderInfo{42281d30 #11 : CursorLoader{42281fe8}}

0 个答案:

没有答案