Override the onCancelled()
mehod then execute the Toast
message from onCancelled()
method.
@Override
protected void onCancelled() {
// Show your Toast
}
Question
When a condition is not satisfied I need to cancel the AsyncTask class UploadPhotos, and notify the user through a Toast. How can I do this?
In my MainActivity
private void InicializeUploadFiles()
{
if(!IsNetworkConected())
ManageConnections();
if(IsNetworkConected())
{
try {
UploadPhotos upload = new UploadPhotos(this);
upload.execute();
}
catch (Exception e){
e.printStackTrace();
}
}
}
In my Asynctask
@Override
protected String doInBackground(Void... args)
{
response = "";
InicializeOwnCloud();
if(IsExistFiles())
SendFolders();
return response;
}
Solution
Override the onCancelled()
mehod then execute the Toast
message from onCancelled()
method.
@Override
protected void onCancelled() {
// Show your Toast
}