Android program to receive data continuously from a server
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
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.
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