Is that possible to check was onCreate called because of orientation change?

后端 未结 8 1450
甜味超标
甜味超标 2020-12-06 00:08

I need to act differently in onStart() method depending on how onCreate() was called in result of orientation change or not. Is that

相关标签:
8条回答
  • 2020-12-06 00:56

    Just check the bundle: when the activity is first started the bundle will be null. If there is an orientation change, it should be non-null.

    From the android docs:

    If the activity is being re-initialized after previously being shut down then this Bundle contains the data it most recently supplied in onSaveInstanceState(Bundle). Note: Otherwise it is null.

    Edit: I don't think you have to supply a bundle in onSaveInstanceState for it to be non-null after an orientation change, but that would be trivial.

    0 讨论(0)
  • 2020-12-06 00:58

    In that case, why don't you handle configuration chanages (orientation) by yourself. Tell android not to handle screen orientation.

    android:configChanges="keyboardHidden|orientation"
    

    Then you just override onConfigurationChanged method to get your rearranging of view or whatsoever things need to be done. Leave things that you don't wanna get executed.

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      //do your jobs 
    }
    
    0 讨论(0)
提交回复
热议问题