How to distinguish whether onDestroy() is called as part of configuration change sequence?

前端 未结 3 1976
天命终不由人
天命终不由人 2021-02-01 20:34

In my Activity some external thing (service) need to be destroyed in onDestroy(). But I do not want this when configuration change happens (e.g. keyboard flips out) because it w

3条回答
  •  太阳男子
    2021-02-01 20:54

    In Android 3.x (API Level 11), you can call isChangingConfigurations() to see if the activity is being destroyed due to a configuration change.

    Prior to that, override onRetainNonConfigurationInstance() and set a boolean data member (e.g., isChangingConfigurations) to true, and check that data member in onDestroy().

提交回复
热议问题