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.