I am trying to pass a function to an Async class, that function suppose to return a result to the calling activity, my best try so far is the following code.
The problem with this is that I defined result
on top so it will be accessible by OnEventCompleteCallBack function, but in the same time I am returning it to the calling activity, it doesn't sound right.
Also, my code involved calling two function to get back the results I need. Is there a better way of achieving this?
Ideally I would like to pass the Function functionIWouldLikeToPass to the Async, but I read that this is not possible in Java (contrary to C#).
My Activity:
Private MyOtherClass result;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
//....
myResult = getResultAsync(str);
//...
}
public MyOtherClass functionIWouldLikeToPass(MyClass myClass){
//do stuff with myClass
//return MyOtherClass type to the result call to the activity
}
public MyOtherClass getResultAsync(String str) {
new AsyncTask_GetSingeValue(new IOnEventCompleteCallBack() {
@Override
public void OnEventCompleteCallBack(MyClass asyncResult) {
result= functionIWouldLikeToPass(asyncResult);
}
}).execute(str);
return result;
}