android_guides icon indicating copy to clipboard operation
android_guides copied to clipboard

Android program to receive data continuously from a server

Open gokulk96 opened this issue 8 years ago • 2 comments

Hi, I am working on this project where i need to receive data contnuosly from a server. Can anyone share code suggestions for the same. I have little experience with android programming and i wish to do this with tcp and sockets.

Thank you

gokulk96 avatar Mar 31 '18 12:03 gokulk96

You can use either Volley or Retrofit to connect with your server. Google's doc about volley -> https://developer.android.com/training/volley/index.html (It has everything, detailed starting from how to add and etc. and here is the github page: https://github.com/google/volley)

Here is Retrofit -> http://square.github.io/retrofit/ . I have never used retrofit but it's same as Volley (As far as I heard from my coworkers and blogs).

If you want to receive data continuously from a server, you might want to use a service (Things running in background) which will pull the data, update your view or data be stored in local sqlite db and you just periodically check whether there is new data and change your view accordingly).

Here is googles doc: https://developer.android.com/guide/components/services.html and you might want to run the service in another process other than on the one where the app is running. Also, service is a bit tricky, so it might take awhile to understand and utilize accordingly. Running a service that checks your server periodically might drain the device battery. There are plenty of resource tho, in youtube/google/github.

shepherd-06 avatar Mar 31 '18 21:03 shepherd-06

Keep in mind that from API 26 (OREO) you have restrictions on background tasks. Android 8.0 Behavior Changes Background Execution Limits Exploring Background Execution Limits on Android Oreo

DonMat avatar Apr 04 '18 12:04 DonMat