- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在设计一个 android 应用程序,它需要在处于 Activity 状态时每分钟播放一次声音。
我的逻辑是使用可运行对象和处理程序在 Activity 状态下每分钟播放一次声音。如果您按下开始或停止按钮,该应用程序可以正常运行。
如果您运行该应用程序并点击停止,它会终止该应用程序。如果您运行该应用程序,声音会继续播放,并且当您重新启动时,计时器将是最新的。这是预期的。
我遇到的问题是,如果你回到家然后启动另一个应用程序,我的应用程序很有可能被杀死并且声音将不再播放(因此当你重新启动时 GUI 将被重置)
我的问题是,我应该使用什么方法让我的应用程序继续播放声音,直到我告诉它停止,即使它不在前台?声音可以被认为是作为对用户的提醒。
我曾尝试使用谷歌机器来帮助我,但我没有运气。
最佳答案
If you run the app hit home the sounds continue to play and when you relaunch the timer will be up to date. This is expected.
除了它不会持续。
The problem i am having is that if you hit home and then launch another app, there is a high chance my app gets killed and the sounds will no longer play (and consequently GUI will is reset when you relaunch)
正确。
What approach should i use so that my app will continue to play the sounds until i tell it to stop, even if its not in the foreground?
A service .在一分钟的时间内,您处于我认为您应该使用 AlarmManager
和 IntentService
的位置与您现有的 Handler
方法可行。
您应该将 startForeground()
与该服务一起使用,既可以防止 Android 将其关闭,也可以为用户提供一种非常简单的方法来返回 Activity 以关闭该服务(通过您通过 startForeground()
建立的 Notification
。
关于android - 如何让 Android 操作系统知道我的应用程序在后台时有事情要做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7961247/
我有一个包含两个项目的解决方案,每个项目都生成一个单独的 dll,供另一个 Windows 应用程序使用。这些项目中的每一个都有一个名为 MyActions 的类,只有一个这样的方法 项目 1
我有一个包含两个项目的解决方案,每个项目都生成一个单独的 dll,供另一个 Windows 应用程序使用。这些项目中的每一个都有一个名为 MyActions 的类,只有一个这样的方法 项目 1
所以我在 if 语句中有这段代码如下 if (!inTime || !moment(inTime).format('m') % 15 === 0) { doSomething(); } 传入的 inT
像往常一样,我想做的比我知道的还多:-D 这就是我正在做的事情......我正在写一篇简历。 但是在简介中,我想要一个“长简介”和一个“短简介”按钮。 长传记显然会显示整个传记,但短传记会捕获列表中的
我正在使用物质。 js创建一个二维场景。我在场景中对一个物体施加力,这个物体撞击其他物体,但最终所有物体都因摩擦和能量损失而停止移动。 我需要以某种方式检测场景中的所有物体何时停止移动。我发现这样
谁能快速浏览一下这段代码,让我知道哪里出错了。 在模糊事件中,.textok 类加载正常,但 .textbad 类加载不正常。 .textok { color:#0F0; background
我的情况是这样的:我有一个项目,它使用了一些生成的代码。在生成的代码中,几乎所有文件中都硬编码了某个 URI。 因此,在某些时候我得到了两个生成的代码库:一个针对开发,另一个针对暂存。 我想通过 Gr
这是一个严肃的问题(见我的评论)。 问题很简单:Java 所做的所有 SEO 不友好的事情有哪些会导致您的网站在主要搜索引擎中的排名不如应有的好? 最佳答案 有一个与 JSESSIONID 相关的 s
我正在使用 PHP。我想完成 jQuery AJAX 进程,(完成进程并数据返回主页后)。 然后执行下一个 jQuery 操作。关于如何做到这一点有什么想法吗? $.ajax({ url: "pa
在释放内存之前,我要从 CPU 缓存中逐出内存范围。理想情况下,我只想放弃这些缓存行而不将它们保存到内存中。因为没有人会使用这些值,无论谁再次获得该内存范围(在 malloc()/new/_mm_ma
我不喜欢 jackson 。 我想使用 ajax,但要使用 Google Gson。 所以我试图弄清楚如何实现我自己的 HttpMessageConverter 以将其与 @ResponseBody
我是一名优秀的程序员,十分优秀!