- You post the
Runnable
toUI Thread
indoInBackground()
which results in pointlessAsyncTask
. lstOutput
is retuned before it is updated so it is always null.if (lstOutput.size() == 0 || lstOutput == null)
will crash if it's null when callingsize()
. Should check for null in first place.
The intention of your code is unclear, but you should probably do it like
private final myReceipt reprintReceipt;
public AsyncTaskName() {
myReceipt reprintReceipt = new myReceipt();
}
@Override
protected List<String> doInBackground(String... urls) {
return reprintReceipt.saveReprint(muncID);
}
@Override
protected void onPostExecute(List<String> response) {
if (response == null || response.isEmpty()){
System.out.println("Failed Sending data");
return;
}
if(response.get(0).equals("SUCCESS")){
}
}
Edit: if the Handler
is created in myReceipt()
constructor, move it's creation to onPreExecute()
or AsyncTask
s constructor if it's called from UI thread.
Anyway, myReceipt.saveReprint() method shouldn't use a Handler
if it's executed in AsyncTask, so there's something totally wrong with your design.