I have an application which uses the MediaPlayer to play music. When I play music and lock my d开发者_运维知识库evice it starts to call onPause and onResume in various periods of time, ( it's not the time of one track )
My log is like this:
07-11 10:08:50.933: INFO/Activity(9956): resume PlayerActivity
07-11 10:08:50.948: INFO/Activity(9956): pause PlayerActivity
07-11 10:08:56.300: INFO/Activity(9956): resume PlayerActivity
07-11 10:08:56.316: INFO/Activity(9956): pause PlayerActivity
07-11 10:09:21.839: INFO/Activity(9956): resume PlayerActivity
07-11 10:09:21.886: INFO/Activity(9956): pause PlayerActivity
07-11 10:09:27.003: INFO/Activity(9956): resume PlayerActivity
07-11 10:09:27.019: INFO/Activity(9956): pause PlayerActivity
07-11 10:18:49.738: INFO/Activity(9956): resume PlayerActivity
07-11 10:18:49.745: INFO/Activity(9956): pause PlayerActivity
Is this normal behaviour of the android Activity ? There where no buttons pressed or anything else done with the device.
Best regards
There is a way to avoid it. I believe this is due to configuration changes when you lock the screen. If your app has landscape orientation and your lock screen has portrait orientation, that's a configuration change. The same is true if you have on screen nav buttons, and those go away for the lockscreen, which causes the screen size to change. In the manifest file, you can change the Config changes for your activity and specify a whole bunch of them. That should stop Android from rebuilding your activity every time you lock the screen and will stop the many onPause - onResume callbacks.
Yes this is the normal behavior of Android. Based on the action that is being performed, the method corresponding to the life cycle will be called. In each case you might have to override the appropriate method to get the result you require.
精彩评论