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

Best practice for Request-Screen-Orientation-Change? #176

Closed frank-fan closed 8 years ago

frank-fan commented 8 years ago

Hi, I manage all my app screens in one activity using mortar & flow. But I got a problem when I have a different orientation screen:

I try to invoke this to change orientation in ViewPresenter.onLoad();

mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

The orientation is changed, but it's the previous screen. I think when ViewPresenter.onLoad, the screen-view is not fully attached.Too soon to request orientation changes, may interrupt the attach-process.

So I add a delay with handler,

private Handler mHandler = new Handler(Looper.getMainLooper());
....
 mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            }
        }, 500);    

It worked, the orientation changed, and the screen is right. But a delay make the experiences miserable.

I'm new to Mortar & path, please help me to solve this problem, thanks!

creativepsyco commented 8 years ago

Thats coz the traversal hasn't completed for the new screen and screen orientation causes the activity to be recreated, which makes the old history be restored. You can try to make the newer history be stored and let the orientation dictate the dispatching:

rjrjr commented 8 years ago

https://github.com/square/flow/pull/204