Issue
I'm trying to get a response back from my public class saveData extends AsyncTask.
I added a public interface but the Android Studio gives me an error for the @Overide
on my onCreate
in the activity.
public class almostFinish extends Activity implements OnTaskCompleted{
@Override // here I get an Error
protected void onCreate(Bundle savedInstanceState) {}
@Override
public void onTaskCompleted(boolean result) {
//ToDo
}
}
My interface.
public interface OnTaskCompleted {
void onTaskCompleted(boolean isSuccess);
}
My AsyncTask class
public class saveData extends AsyncTask<List<String>, Void, Void> {
private OnTaskCompleted listener;
boolean myflag = false;
@Override
public void onPreExecute() {}
@Override
protected Void doInBackground(List<String>... params) { }
@Override
public void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
listener.onTaskCompleted(myflag);
}
}
Thanks for any help.
I'm just getting an Error in the editor: "Annotations are not allowed here" If I remove the @Override then I get an Error telling me to add @Override.
Solution
According this code you will get null pointer exception. because you have not assign the listener in code.
public class saveData extends AsyncTask < List < String > , Void, Void > { private OnTaskCompleted listener; boolean myflag = false; @Override public void onPreExecute() {} @Override protected Void doInBackground(List < String > ...params) {} @Override public void onPostExecute(Void result) { super.onPostExecute(result); onTaskCompleted(myflag); } }
Answered By - Tabassum Latif
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.