How to pause and play media player when screen is locked or sleeps?
问题 I am using Java and xml to create an application for the summer. This app has music in the background, that I would like to pause and then play depending on the state it is in. When i lock my screen the music does not pause it keeps playing. How would i fix this, I have tried to use the method on this site: https://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents I have not been able to successfully get a working prototype, and I am working in android studio.