This is my code:
In onCreate:
new LoadMusicInBackground().execute();
Then towards the end of my main class I have this code
Create asynctask with listener
class ClearSpTask extends AsyncTask {
public interface AsynResponse {
void processFinish(Boolean output);
}
AsynResponse asynResponse = null;
public ClearSpTask(AsynResponse asynResponse) {
this.asynResponse = asynResponse;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
showProgressDialog();
}
@Override
protected Void doInBackground(Void... voids) {
cleardata();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
hideProgressDialog();
asynResponse.processFinish(true);
}
}
And use the Asynctask
new ClearSpTask(new ClearSpTask.AsynResponse() {
@Override
public void processFinish(Boolean output) {
// you can go here
}
}).execute();
I hope this might help some people