开启/关闭手电筒,而应用程序最小化 [英] Turn on/off flashlight while app is minimized

查看:112
本文介绍了开启/关闭手电筒,而应用程序最小化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序有一个活动和服务。该服务continously管理的一些数据。在某些情况下,服务发送的广播请求给活动开启手电筒

In my application I have an activity and a service. The service continously manages some data. In certain cases the service sends a broadcast request to the activity to turn on flashlight.

这工作得很好。然而,当应用程序是(手动或进来的呼叫)最小化,不能正常工作。当我把程序返回到前面就开始工作了。

This works very well. However it does not work when app is minimized (manually or by incomming call). As soon as I bring the app back to the front it starts to work again.

据我观察,我看到该服务仍在运行时,应用程序最小化的日志。然而,由于活性不是present了相机对象不能被访问,以激活手电筒。但是,在日志中没有错误。

As I observed the log I saw that the service is still running when app is minimized. However since the activity is not present anymore the camera object cannot be accessed to activate the flashlight. But there is no error in the log.

为什么手电筒没有激活?如何手电筒被激活时,应用程序最小化?

Why is the flashlight not activated? How can the flashlight be activated when the app is minimized?

推荐答案

只有前台活动可以按住相机。从谷歌文档:

Only the foreground activity can hold the camera. From the Google documentation:

如果你的应用程序不能正确释放相机,所有的后续尝试访问摄像机,包括那些由你自己的应用程序,将失败,并可能导致您或其他应用程序被关闭。

"If your application does not properly release the camera, all subsequent attempts to access the camera, including those by your own application, will fail and may cause your or other applications to be shut down."

您可以尝试声称它的服务,而不是,但我怀疑这会无法正常工作。这真的不是设计这样的工作方式。

You can try claiming it on the service instead, but I suspect that won't work well. It just really wasn't designed to work this way.

这篇关于开启/关闭手电筒,而应用程序最小化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆