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;
}
Was it helpful?

Solution

Override the onCancelled() mehod then execute the Toast message from onCancelled() method.

   @Override
    protected void onCancelled() {
        // Show your Toast 
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top