Sending continuos data from service to activity at really very high speed

烈酒焚心 提交于 2019-12-11 07:30:12

问题


I am developing a testing application on an Architecture which is based on Producer-Consumer structure. I have an producer-consumer* problem, especially if an producer callback mechanism is utilized in android service i.e. consumer. Consumers are not supposed to hold the call for more than the minimum necessary time to have the info handed over. Since the producer’s callbacks are supposed to run in a different thread than the consumer’s one.

In my specific case within the callback of Producer only a reference moving of the passed object should be done and release the control right away. The object has to be consumed in the consumer thread. Currently I have been calling a method which only gets data coming within callback and processes that data and return it via Intent baack to the Android Activity.

Now, Android intents are well known to be resource consuming entities which are not meant (and not supposed) to be used to transfer data streams.

Within the Test app, one intent per callback is generated. Those overflow the whole system. For example, at 25% of load a traffic of about a thousand Android intents per seconds are triggered.

I want a way which doesn't include Android Intents(without any Thrid party jar) using which I can send data back to my android activity or route on host machine at super high rate so that my producer call back doesn't get crashed.


回答1:


Use a socket connection between the Service and the Activity for streaming data. Intent is the wrong technique.



来源:https://stackoverflow.com/questions/35935354/sending-continuos-data-from-service-to-activity-at-really-very-high-speed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!