How to avoid recreating view on onCreate on Android?

前端 未结 11 1756
执笔经年
执笔经年 2021-01-17 22:18

I have a FragmentActivity that shows a contacts list.

Here is my onCreate method:

@Override
protected void onCreate(Bundle          


        
11条回答
  •  礼貌的吻别
    2021-01-17 23:06

    I faced same problem while using Fragments.

    We have existing methods as stated above. If you are finding yourself in difficult position for using that then you can try as mentioned below :-

    • Initiate a Boolean value with false.
    • Set that Boolean value to true after you get your data.
    • Now on re-initiate of your OnCreate() check for that Boolean value to be true or false. if false then you need to pull that data again else you need not to get that data. Put condition for same.

提交回复
热议问题