Question

so I'm implementing androids built in download service and I have three Fragments that have progress bars that need to be updated when the progress changes of the current download... How should I go about doing that? I was thinking using a progress changed callback, but it gets pretty complex and ugly if I'm doing that for 3 Fragments, and also what if one of the Fragments gets deleted and restored? Then that reference is dead, and could cause a memory leek and or a app crash. is there maybe some way of broadcasting the current download progress without an implicate target for that data, so it does not matter if a fragment get's destroyed? any help on this would be greatly appreciated.

Was it helpful?

Solution

You can use the pattern of a UIFragment and WorkerFragment to achieve this. A UIFragment is a standard fragment with UI (overriding onCreateView) and a worker fragment without UI. You have to save the instance of the worker thread across orientation changes and other lifecycle events.

A working example can be found here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top