-
Notifications
You must be signed in to change notification settings - Fork 10
Android users
Rahil khan edited this page Mar 13, 2023
·
3 revisions
Since this library uses AsyncTask library, the callbacks are made on the same background thread, which might not be good for android development (as far as updating UI is concerned).
You need to manually wrap your code into the runOnUiThread()
method inside every callback of the task.
What you can do is create a helper method that takes that AsyncTask as an argument and an interface as a callback.
public void callOnUIThread(AsyncTask task,MyCallback callback){
task.setOnCompleteCallback(new AsyncTask.OnCompleteCallback() {
@Override
public void onComplete(AsyncTask call) {
runOnUiThread(() -> {
if (call.isSuccessful)
callback.onSuccess(call.result);
else
callback.onFailure(call.exception);
});
}
});
}
Here, MyCallback is a helper interface for the callback.