当条件不满足时,我需要取消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();
}
}
}
在我的Asynctask
中@Override
protected String doInBackground(Void... args)
{
response = "";
InicializeOwnCloud();
if(IsExistFiles())
SendFolders();
return response;
}
答案 0 :(得分:1)
覆盖onCancelled()
mehod,然后从Toast
方法执行onCancelled()
消息。
@Override
protected void onCancelled() {
// Show your Toast
}