如何從此AsyncTask中實現的ProgressDialog中取消AsyncTask。在AsyncTask中中止AsyncTask
@Override
protected Void doInBackground(Void... params)
{
try
{
FTPHelper ftpHelper = new FTPHelper(_context);
ftpHelper.SincronizarArquivos();
}
catch...
@Override
protected void onPreExecute()
{
_dialog.setMessage("Aguarde, sincronizando arquivos...");
_dialog.setCancelable(false);
_dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancelar", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
// This not works for cancel AsyncTask
cancel(true);
...
由於doInBackground(Void ... params)中沒有循環,所以我取消或返回。我如何從ProgressDialog中取消AsyncTask?
實例看來,應實現內部'FTPHelper.SincronizarArquivos'方法進行檢查一些標誌,然後只設置該標誌上你'的onClick '回調。 –