I have a question regarding MVP pattern in Android. I want to write my own "application core" which will have base classes for presenters, views etc. It has to be simple, clean and "stable". My idea is very similiar to what Mosby has to offer, I'm trying to achive something like this:
- Each Activity has it's own Presenter, View (interface to communicate with Activity), ViewState (parcelable object that holds persistent data).
When Activity is being destroyed:
- detach View
- save ViewState in bundle
- cancel all background tasks in Presenter (tasks that updates View when finished)
- destroy Presenter
When Activity is being recreated:
- attach View
- restore ViewState
- create new instance of Presenter
- restart background tasks that have been canceled
I've got almost eveything done except that last issue - "restart background tasks that has been canceled". It will be easier to discuss it with an example. So let's say I have two methods in a presenter (Retrofit 2 calls):
- downloadUsers() - fetches users data from web server and onSuccess updates view
- downloadProject() - fetches project info from web server and onSuccess updates view
Now user is changing configuration when one of those calls has been started but not finished yet. How will I know which one of them I should restart when Presenter will be recreated?
The only idea that comes to my mind is create a persitent boolean flag for each task, set it true when task is starting, and false when it is finished. When Presenter will be created I will check every flag and restart corresponding calls.
What do you think about it? How it can be improved? Any other ideas?