AssetManager.update() Loop with Timeout vs. Background finishLoading() Thread: Which Prevents ANR While Showing Progress?
0 reputation · 27 Sept 2024, 23:26 UTC
The goal is to load game assets with libgdx's AssetManager in a way that keeps the main OpenGL render thread responsive enough to avoid Android's "Application Not Responding" warnings, while still being able to display loading progress and to abort or timeout the load if it takes too long.
Constraints include: the main thread must not be blocked for extended periods, progress reporting (e.g., for a progress bar) must remain accurate, and any cancellation or timeout mechanism must not leak resources or break reference‑counted asset sharing. It is unclear whether periodically calling AssetManager.update() in the render loop with a manual timeout check is preferable to offloading AssetManager.finishLoading() to a background thread and monitoring progress via AssetManager.getProgress().
- Which approach better respects the main thread's frame budget and reduces the risk of ANR?
- How can a timeout or cancellation be safely triggered without leaving partially loaded assets or breaking AssetManager's reference counting?
- What are the trade‑offs in implementation complexity and reliability between a render‑loop update() strategy and a background finishLoading() thread?