Periodically fetching data (polling) from the server in Android

后端 未结 3 1270
北荒
北荒 2020-12-29 14:31

I working on the app where I get the data from the server using rest call and add it to the view. I get all the initial data correctly. I use AsyncTask for doing it.

3条回答
  •  臣服心动
    2020-12-29 15:07

    The best way to do it would be to create a service that fetches the data from the server. Afterward if your activity is running, the service can send an intent to the activity with the fetched data.

    Or, have the service run when your app runs and have your activity bind to the service when it start up. Then use AIDL or something similar to communicate with the service.
    (For example, every time the service has fetched data, it can fire off a callback function in your activity)

提交回复
热议问题