问题描述
我开发一个应用程序,它有多个活动。用户可以浏览到的任何活动。我开始从第一个主要活动的背景音乐,它一直播放整个应用程序。现在我想,只要用户presses HOME键,媒体播放器应该暂停播放,当用户回来的应用程序,它开始再次播放。首先,我做的媒体播放器的静态,并暂停音乐的onPause()和onResume()打不过它创建了一个混蛋,而活动之间的切换。我希望你有我的观点。任何想法如何暂停时,HOME键pressed玩,玩一遍,当用户回来?
I am developing an app which has multiple activities. User can navigate to any activity. I start background music from first main activity and it keeps playing throughout the application. Now I want that whenever user presses HOME key, the media player should pause playing and when user comes back to app, it starts playing again. First I made media player static and was pausing music in onPause() and playing in onResume() but it creates a jerk while switching between activities. I hope you got my point. Any idea how to pause playing when HOME key pressed and play it again when user comes back?
推荐答案
看看的的()
古称活动周期的一部分,当活动即将 进入背景作为用户选择的结果。例如,当 用户presses Home键,onUserLeaveHint()将被调用,但 当电话呼叫到来使得在呼叫活动是 自动被推上前台,onUserLeaveHint()将不 呼吁活动被中断。在情况下,当它被调用时, 这种方法活动的的onPause()回调之前,右边的叫。
这篇关于当Home键pressed的Android停止背景音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!