In most of the case, when dealing with case
- User thread (
AsyncTask
) to perform background processing - Pass back calculated result back to
Activity
orFragment
Activity
orFragment
re-creation might happen before user thread finishes its background processing
So far, from many reliable sources, I can see the recommended way is using Retained Fragment
Sources
- Best practice: AsyncTask during orientation change
- http://www.vogella.com/tutorials/AndroidBackgroundProcessing/article.html
- http://www.androiddesignpatterns.com/2013/04/retaining-objects-across-config-changes.html
From time to time, I heard event bus libraries is good for handling relations between Activities, Fragments, and background threads. (Please refer to https://github.com/greenrobot/EventBus. It states that performs well with Activities, Fragments, and background threads)
I came across some really popular event bus libraries
I was wondering, when comes to handle relations between Activities, Fragments, and background threads, how is event bus approach different from Retained Fragment approach?
Which ways is a recommended way?