0
最近,我一直試圖通過從服務器緩存數據來使我的Android應用程序更好。經過一些研究後,我決定採用Loader模式,因爲它爲我處理了很多情況。BackStack上的碎片上的加載程序未保留
使用com.android.support:appcompat-v7:23.4.0
我設法拿到裝載機保存響應當設備旋轉或穿越回了返回堆棧時的項目時重新顯示。
問題是,當我在活動片段管理器的Back Stack上放置一些片段時,旋轉設備,然後開始備份Back Stack。
這些重新顯示的片段的加載程序被重新創建,而不是從第一次顯示的時候使用加載程序。
這裏是從LoaderManager.enableDebugLogging(true);
輸出:
V/LoaderManager: initLoader in LoaderManager{8ddafd2 in HostCallbacks{6208a3}}: args=null
V/LoaderManager: Created new loader LoaderInfo{97187a0 #0 : DemoAppLoader{269af59}}
V/LoaderManager: Starting in LoaderManager{8ddafd2 in HostCallbacks{6208a3}}
V/LoaderManager: Starting: LoaderInfo{97187a0 #0 : DemoAppLoader{269af59}}
D/DemoApp: MainActivity: -> http://jsonplaceholder.typicode.com/posts {"body":"Post 0:
D/DemoApp: MainActivity: <- http://jsonplaceholder.typicode.com/posts {
"body": "Post 0: Nothing here!",
"title": "Fake 0",
"user_id": 0,
"id": 101
}
V/LoaderManager: onLoadComplete: LoaderInfo{97187a0 #0 : DemoAppLoader{269af59}}
V/LoaderManager: onLoadFinished in DemoAppLoader{269af59 id=0}: Response{fde91b}
E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f75650179a0
V/LoaderManager: Stopping in LoaderManager{8ddafd2 in HostCallbacks{6208a3}}
V/LoaderManager: Stopping: LoaderInfo{97187a0 #0 : DemoAppLoader{269af59}}
V/LoaderManager: initLoader in LoaderManager{3e8cbf6 in HostCallbacks{6208a3}}: args=null
V/LoaderManager: Created new loader LoaderInfo{e87fbf7 #1 : DemoAppLoader{6b5ba64}}
V/LoaderManager: Starting in LoaderManager{3e8cbf6 in HostCallbacks{6208a3}}
V/LoaderManager: Starting: LoaderInfo{e87fbf7 #1 : DemoAppLoader{6b5ba64}}
D/DemoApp: MainActivity: -> http://jsonplaceholder.typicode.com/posts {"body":"Post 1:
D/DemoApp: MainActivity: <- http://jsonplaceholder.typicode.com/posts {
"body": "Post 1: Nothing here!",
"title": "Fake 1",
"user_id": 0,
"id": 101
}
V/LoaderManager: onLoadComplete: LoaderInfo{e87fbf7 #1 : DemoAppLoader{6b5ba64}}
V/LoaderManager: onLoadFinished in DemoAppLoader{6b5ba64 id=1}: Response{1cdb182}
E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f7565017a10
V/LoaderManager: Retaining in LoaderManager{3e8cbf6 in HostCallbacks{6208a3}}
V/LoaderManager: Retaining: LoaderInfo{e87fbf7 #1 : DemoAppLoader{6b5ba64}}
V/LoaderManager: Destroying Active in LoaderManager{8ddafd2 in HostCallbacks{6208a3}}
V/LoaderManager: Destroying: LoaderInfo{97187a0 #0 : DemoAppLoader{269af59}}
V/LoaderManager: Reseting: LoaderInfo{97187a0 #0 : DemoAppLoader{269af59}}
V/LoaderManager: Destroying Inactive in LoaderManager{8ddafd2 in HostCallbacks{6208a3}}
V/LoaderManager: Destroying Active in LoaderManager{8ddafd2 in HostCallbacks{6208a3}}
V/LoaderManager: Destroying Inactive in LoaderManager{8ddafd2 in HostCallbacks{6208a3}}
V/LoaderManager: Destroying Inactive in LoaderManager{3e8cbf6 in HostCallbacks{6208a3}}
E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f7565017930
V/LoaderManager: initLoader in LoaderManager{3e8cbf6 in HostCallbacks{5abbb3d}}: args=null
V/LoaderManager: Re-using existing loader LoaderInfo{e87fbf7 #1 : DemoAppLoader{6b5ba64}}
V/LoaderManager: Starting in LoaderManager{3e8cbf6 in HostCallbacks{5abbb3d}}
V/LoaderManager: onLoadFinished in DemoAppLoader{6b5ba64 id=1}: Response{1cdb182}
V/LoaderManager: Finished Retaining in LoaderManager{3e8cbf6 in HostCallbacks{5abbb3d}}
V/LoaderManager: Finished Retaining: LoaderInfo{e87fbf7 #1 : DemoAppLoader{6b5ba64}}
V/LoaderManager: onLoadFinished in DemoAppLoader{6b5ba64 id=1}: Response{1cdb182}
E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f7565017cb0
E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f7565017460
V/LoaderManager: Stopping in LoaderManager{3e8cbf6 in HostCallbacks{5abbb3d}}
V/LoaderManager: Stopping: LoaderInfo{e87fbf7 #1 : DemoAppLoader{6b5ba64}}
V/LoaderManager: Destroying Active in LoaderManager{3e8cbf6 in HostCallbacks{5abbb3d}}
V/LoaderManager: Destroying: LoaderInfo{e87fbf7 #1 : DemoAppLoader{6b5ba64}}
V/LoaderManager: Reseting: LoaderInfo{e87fbf7 #1 : DemoAppLoader{6b5ba64}}
V/LoaderManager: Destroying Inactive in LoaderManager{3e8cbf6 in HostCallbacks{5abbb3d}}
V/LoaderManager: Destroying Active in LoaderManager{3e8cbf6 in HostCallbacks{5abbb3d}}
V/LoaderManager: Destroying Inactive in LoaderManager{3e8cbf6 in HostCallbacks{5abbb3d}}
V/LoaderManager: initLoader in LoaderManager{b5dd22c in HostCallbacks{5abbb3d}}: args=null
V/LoaderManager: Created new loader LoaderInfo{70414f5 #0 : DemoAppLoader{59dc28a}}
V/LoaderManager: Starting in LoaderManager{b5dd22c in HostCallbacks{5abbb3d}}
V/LoaderManager: Starting: LoaderInfo{70414f5 #0 : DemoAppLoader{59dc28a}}
D/DemoApp: MainActivity: -> http://jsonplaceholder.typicode.com/posts {"body":"Post 0:
D/DemoApp: MainActivity: <- http://jsonplaceholder.typicode.com/posts {
"body": "Post 0: Nothing here!",
"title": "Fake 0",
"user_id": 0,
"id": 101
}
V/LoaderManager: onLoadComplete: LoaderInfo{70414f5 #0 : DemoAppLoader{59dc28a}}
V/LoaderManager: onLoadFinished
您是否使用24.0.0支持庫進行過試用?許多片段問題,例如[this one](https://code.google.com/p/android/issues/detail?id=200927)在該版本中修復了 – ianhanniballake
更新至24.0.0確實解決了我遇到的問題。不幸的是,它要求我也將該項目更新到JDK 8,這有點極端,但我想這是值得的。如果你想實際上將其作爲解決方案,我會除外。 –
是的,編譯API 24(使用v24支持庫的要求)需要Java 8。 – ianhanniballake