Search code examples
androidgpsclientserverdata-synchronization

Android client server app sharing gps data


I am developing android application which allow users to share localization data between them, and showing it on the map. I've done it, and its working but I am looking for better performance, or just better pattern for app like this. For now, my app uses https connection between android client and REST servlet on tomcat. For instance, if user is logged he is sending his gps data every 10 sec to server, and gets other users positions. Everything by HTTP POST.

First thing I want to ask you:

Does anyone knows better solution to sync data with server than android service with timed task every 10 sec? I have background service that is running all the time and every 10 sec runs AsyncTask which asking server about users localizations.

And what do you think about connection method with server? Maybe it will be better to create connection by sockets?

Thanks in advance for all responses.


Solution

  • You're right. There is no necessity of establishing http connection each 10 seconds. It's absolutely inefficient for clients and your server in terms of CPU usage and data transferring.

    There're two solutions which I suppose more appropriate for you task:

    1. Yes, sockets. Socket connection could be fairly easy implemented on Аndroid. Two threads which share socket connection: first one reads data, second one writes data. To receive data when phone is sleep you could use GCM service.

    2. P2P connection. It's quite reasonable because as I understood you don't need to modify or track transferring data by your server. Clients just will communicate with each other.