Issue
everyone!
I'm building an app for the company where I work and we have to run an interaction with an API in the background, but while this interaction is running, the interaction sends us some messages that must enable/disable some views in activity/fragment.
We are running this interaction using the async task, but the problem is: I can't update a view attribute when the message comes from a background thread. I had to use a custom Progress class to handle those messages and then change the view attributes.
In our app, we are using MVVP pattern, and my async task is called from a ViewModel, which is responsible for execute the bizness logic.
But what I really want to know is: Is there another way to perform an async task without using an AsyncTask subclass? Maybe some of you guys can halp me out recommending a way that use callbacks to notify messages and when the function ends.
I know that Retrofit makes an asynchronous task using the enqueue method, but I didn't understand how can I implement that way by myself.
Ps.: The AsyncTask subclass is working fine, but I didn't get along with that implementation.
Solution
You can take a look at libraries like retrofit for performing API calls. Also, if you are using kotlin you can take a look at coroutines for a more generic asyncronous work.
Answered By - Eric Martori
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.