How to refresh an Android RelativeLayout when orientation changes without restarting the Activity?

后端 未结 2 1367
误落风尘
误落风尘 2021-01-28 04:07

I have an Android Activity with a RelativeLayout and I have implemented the following method to prevent the activity from being recreated on change of Orientation:



        
2条回答
  •  灰色年华
    2021-01-28 05:00

    You have two ways:

    • Retaining an Object During a Configuration Change
    • Handling the Configuration Change Yourself

    You have chosen the second way. In this case you have to reassign every resource by hand and this approach is not recommended.

    IMHO the best way is the first by implementing the method: onRetainNonConfigurationInstance();

    Here a complete example on howto use.

    Note: the onCreate will be called again but you can adjust your code to prevent long runnning task to be called again during a configuration change

提交回复
热议问题