1

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.

Pawankumar Dubey
  • 387
  • 1
  • 6
  • 21

1 Answers1

1

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

David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • if both Service and Activity are hosted by the same process, a "bound local service" pattern would be optimal: no need for any system API for direct communication, if they are hosted by different processes see [this](http://stackoverflow.com/a/33688843/2252830) (pipes are not only faster than sockets, but also the code is much simple) – pskink Mar 14 '16 at 19:37
  • 1
    @pskink why don't you create a new answer instead of commenting on mine? – David Wasser Mar 14 '16 at 21:36
  • Thanks David, Considering my requirement i tried doing exactly same but instead doing it for Service to UI now i am directly dumping data on my Window machine using Socket programming. My client provided display didn't support wifi so i am now sending data from android OS to windows via USB. I am keen to understand adb forward tcp:xyz tcp:pqr since now i have to have multiple ports for data streaming. – Pawankumar Dubey Mar 17 '16 at 15:05