How do I tell when a configuration change is happening in Froyo?

前端 未结 5 1514
梦谈多话
梦谈多话 2021-02-08 13:18

In my app, I want a media file to play, and to keep playing if the user rotates the screen (destroying the Activity), but I want it to stop playing if the user moves to a differ

5条回答
  •  长发绾君心
    2021-02-08 13:49

    Prior to Honeycomb, onRetainNonConfigurationInstance() as mentioned in the accepted answer is the best way to do this.

    Starting with Honeycomb, that's deprecated, but there is a much simpler way: call isChangingConfigurations() instead, during any of your onPause()/onStop()/onDestroy().

    Finally, if using the support library FragmentActivity ( android.support.v4.app.FragmentActivity) on pre-Honeycomb, onRetainNonConfigurationInstance() is declared final, but you can override onRetainCustomNonConfigurationInstance() instead for the same effect.

提交回复
热议问题