Android - 当屏幕超时时如何写入文件

发布于 2024-12-05 07:57:03 字数 411 浏览 0 评论 0原文

我们正在编写一个(行业特定的)应用程序来维护它自己的日志文件(我知道我们应该使用android日志,但出于商业目的,我们需要以非常特定的格式维护这个日志文件。)这个应用程序不适合大众市场,并且用户将清楚地意识到应用程序将遭受的电池消耗。

首先,应用程序有一项服务必须始终保持与服务器的连接。我们通过使用部分唤醒锁实现了这一点,一旦屏幕超时,它就会按预期工作。

然而,我们的问题是,当屏幕超时时,我们的记录器模块停止写入位于外部存储上的文件,一旦屏幕再次启动,记录器会在短时间内恢复。

我们知道该应用程序没有被系统杀死(由于前台服务),因为当它重新启动时,一切都保持原样。 (重新启动使我们回到不同的屏幕)

是否有另一种方法可以强制系统保持文件流打开?为什么我们持有的部分唤醒锁还没有做到这一点?

必须有一种方法可以随时写入文件。

We are writing an (industry specific) application that maintains it's own log file (I know we should use the android log, but for business purposes we need to maintain this log file in a very specific format.) This app is not for mass market, and users will be well aware of the battery drain the app will suffer.

First the app has a service that must maintain a connection to a server at all times. We have achieved this through the use of a partial wakelock, which works as expected once the screen time's out.

Our problem however, when the screen time's out, our logger module ceases to write to a file located on external storage, once the screen is started again the logger resumes after a short period.

We know the app isn't being killed by the system (due to the foreground service) as when it is restarted everything remains as it should. (A restart brings us back to a different screen)

Is there another way to force the system to keep the stream to the file open? Why does the partial-wake-lock we hold not do this already?

There must be a way we can write to file at all times.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

逐鹿 2024-12-12 07:57:03

没有看到代码就很难说。根据您的描述,部分唤醒锁是最好的选择,它应该防止 CPU 进入睡眠状态,这样只要您持有唤醒锁,您就可以运行您喜欢的任何代码。从您的描述来看,这听起来像是部分唤醒锁没有生效。检查代码以确保您正在执行诸如在设备显示屏进入睡眠状态时释放唤醒锁之类的操作。

Without seeing the code it is hard to say. Given your description a partial wake lock is the best choice, it should prevent the CPU from going to sleep so that you can run whatever code you like for as long as you hold the wakelock. From your description it simply sounds like the partial wake lock is not taking effect. Check the code to make sure you are doing something like releasing the wakelock when the device display goes to sleep.

往日 2024-12-12 07:57:03

事实证明,这是一个设备/平台特定的问题,因为随着时间的推移,问题已经自行解决!

This turned out to be a device/platform specific issue, as the problem has fixed itself over time!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文