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

后端 未结 8 1491
甜味超标
甜味超标 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.

提交回复
热议问题