square / mortar

A simple library that makes it easy to pair thin views with dedicated controllers, isolated from most of the vagaries of the Activity life cycle.
Apache License 2.0
2.16k stars 156 forks source link

ViewPresenter onSave is awkward with Flow #187

Open Kritarie opened 8 years ago

Kritarie commented 8 years ago

I've been struggling to come up with a clean solution to this problem. The BundleService does a great job of allowing my ViewPresenters to save and restore their state on orientation change. Unfortunately, when I navigate from screen to screen with Flow, the View's onSaveInstanceState is called, and not my Presenter's onSave.

I've tried a number of things including:

The two solutions that would actually work, but that I'm not super excited about, are:

Possible solution that, admittedly, may be out of scope for the BundleService is to allow saving state not necessarily tied to the Activity's lifecycle. So in my dispatcher I could call through to traversal.getState(key).save(outgoingView) as normal, and then call BundleServiceRunner.save(key? bundle? state?) and similarly for restoring the incomingView. Then, when my Presenter's onLoad is called, the Bundle for that key is passed down.

Zhuinden commented 7 years ago

I ran into this problem and the solution was to get rid of Mortar's ViewPresenters and just use Flow's state persistence directly instead.