How to avoid recreating view on onCreate on Android?

前端 未结 11 1759
执笔经年
执笔经年 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 22:45

    You are going to check controller therefor.

    Instead of that try to check value you stored. First take one variable as Bundle. Save it in onCreate method.

    Bundle bdlSaveInstant;   // Declare at top before onCreate() method.
    /* Initialise in onCreate() method. After 
    
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_human_list);
    bdlSaveInstant = savedInstanceState;
    */
    
    @override
    onBackPressed()
    {
      bdlSaveInstant.putBoolean("displayed_contacts", true);
    }
    
    @override
    onDestroy()
    {
      bdlSaveInstant.putBoolean("displayed_contacts", true);
    }
    

    Try this will work.

提交回复
热议问题