Implent An Asynctask Callback Function Returning Multiple Values?
I'm trying to understand how AsyncTask callbacks work. This is how my MainActivity looks so far: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(save
Solution 1:
Your structure is not completely correct because you have 3 parameters in the Activity usage, but your AsyncTask should be "calling back" to the interface listener with some result.
For example
@Override
public void onPostExecute(Result result) {
if (listener != null) {
listener.onTaskCompleted(result);
}
}
So, you need to update the interface method to accept a parameter.
Then you need to pass in an implementation of that interface & method (or anonymous class) to the AsyncTask, then you have a callback.
Regarding the calling of multiple methods, you can use multiple callbacks for different tasks, but it really depends on your end goal.
Post a Comment for "Implent An Asynctask Callback Function Returning Multiple Values?"