机器人长时间插槽收听器 [英] Android long-duration socket listener

查看:99
本文介绍了机器人长时间插槽收听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公司已经在本质上进行的一个项目,与运行Android的智能手机的股票取代了它的一些寻呼机。只要他们签署的,该装置应监听某一插座从服务器接收页面。我幼稚的做法是创建一个前台服务,1)拉开序幕监听线程,和2)持有PARTIAL_WAKE_LOCK。

My company has, in essence, undertaken a project to replace some of its pagers with stock smartphones running Android. As long as they are signed in, the device should be listening on a particular socket to receive "pages" from a server. My naive implementation was to create a foreground service that 1) kicked off a listening thread, and 2) holds a PARTIAL_WAKE_LOCK.

这工作得很好,除非该设备有很长的一段时间不活动,1+小时。然后,似乎操作系统关闭我的应用程序的过程中,可以理解认为它是不使用的。

This works fine unless the device has a long period of inactivity, 1+ hours. Then, it appears that the OS shuts down my app's process, understandably believing it to be not in use.

我完全理解他们这样做的原因,但我想知道如果我能以某种方式解决这个限制。是否有办法信号的Andr​​oid,我的过程中,以永葆/设备清醒还真是够重要吗?我学会了Java和这个项目的Andr​​oid的API,所以有很多地方我的知识是不完整的。

I completely understand their reasons for doing so, but I'm wondering if I can somehow get around this restriction. Are there ways to signal Android that my process really is important enough to keep alive/the device awake? I learned both Java and the Android API for this project, so there are plenty of areas where my knowledge is incomplete.

如果做不到这一点,因为我的业务需求的描述,建议你将如何实现这个功能?当用户登录到我们的自定义应用程序,该装置应始终听。

Failing that, given the description of my business needs, how would you suggest implementing this functionality? While the user is signed in to our custom app, the device should always be listening.

感谢大家阅读了这个问题。

Thanks to everyone for reading this question.

推荐答案

如果您使用的是Service.startForground操作系统不会杀了你的进程()。这就好比音乐播放的使用有什么事情,你不会想一定量的时间后,那些被杀死。

The OS won't kill your process if you are using Service.startForground(). This is what things like music playback use, and you wouldn't want those to be killed after some amount of time.

这是说,对于这种你一般不会需要让你的服务前台的东西 - 当系统没有杀死你的过程,因为它一直坐在周围或者需要的内存,它仍然知道服务要剩余运行,所以在那之后不久将重新启动该服务。这就是谷歌自己的服务工作,他们有一个.apk文件有,保持网络连接打开到谷歌服务,报告回来时,有趣的事情应该像同步新的电子邮件进行后台服务运行,检索和提供C2DM意图等。

That said, for this kind of thing you generally wouldn't need to make your service foreground -- when the system does kill your process because it has been sitting around or needs the memory, it still knows the service wants to remaining running so will restart the service shortly after that. This is how Google's own services work, they have one .apk that has a background service running that keeps a network connection open to a Google service which reports back when interesting things should be done like sync new e-mail, retrieve and deliver a C2DM Intent, etc.

此外,你应该的没有的全部过程中的时间持有唤醒锁。你会杀了电池,特别是对那些喜欢用三星的蜂鸟处理器的一些设备。正确的方法做,这是刚刚离开插座打开,让设备入睡。如果将数据传递到插座,CPU将唤醒提供的数据,在这个时候,你应该获得一个局部唤醒锁只为你需要阅读和处理数据的时间。

Also you should not hold a wake lock during all of that time. You will kill the battery, especially on some devices like those with Samsung's Hummingbird processor. The right way to do this is to just leave the socket open and let the device fall asleep. If data is delivered to the socket, the CPU will wake up to deliver that data and at that point you should acquire a partial wake lock just for the time you need to read and process the data.

这篇关于机器人长时间插槽收听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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