Maintaining Progress Bar Visibility with Orientation Change

前端 未结 3 1793
小蘑菇
小蘑菇 2021-01-23 07:03

I have a progress bar (swirly waiting style) defined in xml as:



        
3条回答
  •  伪装坚强ぢ
    2021-01-23 07:26

    Using android:configChanges is bad practice, because it might get you in much worse trouble.

    Also saving a variable at onSaveInstanceState didn't work for me, since you won't get updates while the Activity is destroyed.

    I ended up using a ResultReceiver inside a Fragment that doesn't get destroyed by using setRetainInstance(true).

    A good article concerning this problem can be found here: https://www.androiddesignpatterns.com/2013/04/retaining-objects-across-config-changes.html

    Also see my answer here: https://stackoverflow.com/a/54334864/6747171

提交回复
热议问题