I am new to android and java programming but I have been given a task to finish an app that a contractor started. I looked up and found how to call an ASync task and wait for it to finish but I can't get it to work. In fact, it won't even compile. I copied it right from one of the answers in How to get the result of OnPostExecute() to main activity because AsyncTask is a separate class?
The errors I get are below. They come in MyCalling class. I appended ***** to the end of the line that has the error
error:
processFinish(String) in <anonymous
com.zoeller.z_controlmobile.MyCallingClass$2> cannot implement
processFinish(String) in AsyncResponse
attempting to assign weaker access privileges; was public
and
error: incompatible types: AsyncTask<String,String,String> cannot be
converted to MyASyncClass
My code is below
public class MyCallingClass extends ActivityBase {
private String _result = null;
protected void onCreate(Bundle savedInstanceState) {
callingMethod();
}
protected void callingMethod() {
MyASyncClass whatever = new MyASyncClass(new MyASyncClass.AsyncResponse() {
@Override
void processFinish(String output) { *****
_result = output;
}
}).execute();
}
// More work done here
}
public class MyASyncClass extends AsyncTask<String, String, String> {
public interface AsyncResponse {
void processFinish(String output);
}
public AsyncResponse delegate = null;
public DeviceConnect(AsyncResponse delegate){
this.delegate = delegate;
}
@Override
protected String doInBackground(String... params) {
// Does the work
}
@Override
public void onPostExecute(String result) {
delegate.processFinish(result);
}
}