[英]How can I keep running an activity when screen is off or locked in Android studio in Java?
I am developing an App, which can play a tone at a fixed frequency to the users by using the Audiotrack Java class.我正在开发一个应用程序,它可以通过使用音轨 Java class 以固定频率向用户播放音调。 Now the sound can be played when a button is pressed, I want to keep the sound keep playing when the screen is off, because the users may want to listen to the sound for 20 minutes at night where doesn't require the screen on all the time.
现在按下按钮可以播放声音,我想在屏幕关闭时保持声音继续播放,因为用户可能希望在晚上听声音20分钟而不需要所有屏幕时间。 Anyone can help with this?
任何人都可以帮助解决这个问题吗?
I have tried the WakeLock according to other posts on Stack overflow, but it doesn't work.我已经根据 Stack Overflow 上的其他帖子尝试了WakeLock ,但它不起作用。 when I go to the activity, the app stops and quits.
当我 go 到活动时,应用程序停止并退出。
To keep sound playing when the screen is off, use a foreground service to play the sound and when the user clicks the start button, you should start your service要在屏幕关闭时继续播放声音,请使用前台服务播放声音,当用户单击开始按钮时,您应该启动您的服务
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.