是否有可能停止的AsyncTask而doInBackground运行? [英] Is it possible to stop asynctask while doInBackground running?

查看:183
本文介绍了是否有可能停止的AsyncTask而doInBackground运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建作为ActivityB的OnCreate异步任务()。
在这个任务我正在一个无限while循环中的 doInBackground()虽然我移动到previous活性的研究,并配备再次向activityB,另一个异步任务得到了创建。

I'm creating as async task in the ActivityB Oncreate(). In that task i'm running a infinite while loop in doInBackground() While i'm moving to previous acitivity and comes again to the activityB, another async task got created.

我的问题现已有二无限while循环运行。是否有可能停止异步任务,当我移动到previous活动?

My Problem is now two infinite while loop is running. Is it possible to stop the async task when i move to previous activity?

推荐答案

当然...检查出的 isCancelled()

public Void doInBackground( .... ) {

   while( !isCancelled() ) {
       ...endless activity...
   }

   return null;
}

这篇关于是否有可能停止的AsyncTask而doInBackground运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆