简体   繁体   English

当屏幕关闭或锁定在 Java 的 Android 工作室中时,如何继续运行活动?

[英]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.

相关问题 当我更改活动以继续计算 Android Studio 中的时间时,如何让我的计时器计数? - How can I let my Timer Count when I change the activity to keep counting the time in Android Studio? 设备处于锁定状态且屏幕处于关闭状态时,如何运行我的应用程序? - How can I run my application when device is in locked state and screen is in turned off state? android屏幕关闭时如何保持IOIO连接? - How to keep IOIO connected when android screen goes off? 按下电源按钮(屏幕关闭)时,Android SQLite数据库被锁定 - Android SQLite database is locked when pressing power button (screen off) 屏幕关闭时如何开始活动? - How do i start activity when screen goes off? 屏幕锁定后如何保持android相机闪光灯打开 - How to keep android camera flash on after screen locked 更改屏幕方向时如何控制android webview活动的更改? - How can I control android webview activity changes when I change screen orientation? 如何在Java Swing中在屏幕上切换形状? - How can I toggle shapes on and off screen in Java Swing? Android:当我在另一个活动中时,如何保持倒计时计时器运行并在超时时显示消息? - Android: How to keep count down timer running and display a message when time out , while I am in another activity? Android Studio Java:如果产品已经存在于我的购物车活动中,我该如何更新我的数量? - Android Studio Java: How can I update my quantity if the product already exist's in my Cart Activity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM