Android 中 Activity 被杀死前的振动/蜂鸣声
我想在所有工作完成后显式终止我的活动,所以我使用:
android.os.Process.killProcess(android.os.Process.myPid());
我还想通过事先振动/蜂鸣来通知用户,所以代码如下所示:
beep();
android.os.Process.killProcess(android.os.Process.myPid());
问题是 Android 似乎会缓存蜂鸣操作,直到整个活动已处理完毕。在这种情况下,活动被强制关闭,因此蜂鸣动作实际上从未执行,因此我永远听不到声音。
这个问题有解决办法吗?
I'd like to explicitly terminate my activity after all the work is done, so I use:
android.os.Process.killProcess(android.os.Process.myPid());
I also want to notify user by vibrating/beeping beforehand, so the codes look like:
beep();
android.os.Process.killProcess(android.os.Process.myPid());
The problem is that Android seems to cache the beep action until the whole activity is processed. In this case, the activity is force closed so that the beep action is actually never executed, so I never hear the sound.
Is there a solution to this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
杀死这个进程似乎有点极端。您是否尝试过使用
Activity.finish()
?http://developer.android.com/reference/android /app/Activity.html#finish()
Killing the process seems a bit extreme. Have you tried using
Activity.finish()
?http://developer.android.com/reference/android/app/Activity.html#finish()
您可以使用,
而不是使用 Process.killProcess()。我亲自使用过它,并且活动终止似乎很顺利。因为,你正在杀死这个过程,当你仍在其中时,你正在接近力量。
希望这能解决您的问题!
You could use,
instead of using Process.killProcess(). I've personally used it, and the activity termination seemed to be smooth. Since, you're killing the process, while you're still in it, you're getting the force close.
Hope this solves your problem!!