onCreate() and onCreateView() invokes a lot more than required (Fragments)

前端 未结 6 2035
不知归路
不知归路 2021-01-30 10:19

Can somebody explain why the onCreate() and onCreateView() are being invoked so many times which increments with each orientation change?

Here

6条回答
  •  难免孤独
    2021-01-30 11:05

    An orientation change causes the system to go through the process of saving instance state, pausing, stopping, destroying, and then creating a new instance of the activity with the saved state. So this is the reason why there is so much onCreate and onCreateView calls.

    I do not think the if (savedInstanceState == null) condition in the onCreate method is a good idea; the state-saving mechanism will not work properly...

提交回复
热议问题