• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Application design for posting fast data to web app server

I have developed android app that reads car's OBD port data on my Android phone via Bluetooth. I could able to read the complete data in phone but I would like to upload that data from my phone to remote app server. Data coming from car is very fast. How I should use AsyncTask and Threads effectively to avoid frame loss?

Thanks in advance.
 
Interesting problem. So you would like to stream the data to a remote server, in parallel with reading it from the car?
This will involve two threads running simultaneously. It's a classic producer/consumer pattern. The two threads will communicate via some shared resource, which is a data structure that can store your items. The data structure absolutely must be synchronized, and thread safe.
Fortunately Java has a ready-made data structure which is perfect for this situation. It's called BlockingQueue.

http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/BlockingQueue.html

This is an interface, so you'll need to use one of the implementing classes. I would go for LinkedBlockingQueue

http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/LinkedBlockingQueue.html

which is a FIFO data structure, so it preserves the order of insertion, and removal.

You producer will be reading data from the car, and the consumer will be taking data out of it and doing the upload. You may want to implement some kind of batch upload, to optimise the performance.
 
Back
Top Bottom