antoniolg / androidmvp

MVP Android Example
5.93k stars 1.58k forks source link

Scrren rotation #20

Closed spartacus777 closed 6 years ago

spartacus777 commented 8 years ago

What about screen rotation scenario? MVP helps majorly with it, and you did not implement it. Would be great if presenters would be saved during activity recreation (rotation) with the help, for ex. retainedFragment. I implemented on your example my MVP model, if it is right and you have time, implement it, please, your repo really hepls peaople understand mvp consept repo - https://github.com/spartacus777/MvpSample

Knight704 commented 8 years ago

@spartacus777 hello, from my humble point of view, I've experienced that using Dagger2 scoped singletons is easier and more flexible. Sometimes though, this can introduce next limitation for which I haven't find proper solution: I cannot provide components that depends on activity-staff in the same scope with scoped singletons that should be retained across config changes. i.e I cannot use module which provides singleton presenter and something that related to current live activity.

RajuSE commented 7 years ago

As @spartacus777 correctly said, Use of singletons is required. You may use android annotations or digger2. Moreover, use Mortar library which provides its BundleService, which gives any View (or any object with access to the Activity context) safe access to the Activity lifecycle's persistence bundle. So screen rotation is handled.