0

当条件不满足时,我需要取消 AsyncTask 类 UploadPhotos,并通过 Toast 通知用户。我怎样才能做到这一点?

在我的 MainActivity

private void InicializeUploadFiles()
{
    if(!IsNetworkConected())
        ManageConnections();

    if(IsNetworkConected())
    {
        try {
            UploadPhotos upload = new UploadPhotos(this);
            upload.execute();
        } 
        catch (Exception e){
            e.printStackTrace();
        }
    }
}

在我的异步任务中

@Override
protected String doInBackground(Void... args) 
{
  response = "";

  InicializeOwnCloud();

  if(IsExistFiles())
      SendFolders();

  return response;
}
4

1 回答 1

1

覆盖方法然后从方法onCancelled()执行Toast消息。onCancelled()

   @Override
    protected void onCancelled() {
        // Show your Toast 
    }
于 2014-04-09T17:35:17.290 回答