2016-05-31 79 views

回答

1

后台任务将继续处理。

从文档:

如果设置,以及正在启动的活动在目前的任务已经运行,然后,而不是在它的上面推出该活动的一个新实例,其他所有活动将被关闭,并且这个意图将作为新的意图被传递到(现在在上面的)旧活动。

如何工作AsyncTask? 让我们来看看的AsyncTask来源:

/** 
    * Creates a new asynchronous task. This constructor must be invoked on the UI thread. 
    */ 
    public AsyncTask() { 
     mWorker = new WorkerRunnable<Params, Result>() { 
      public Result call() throws Exception { 
       mTaskInvoked.set(true); 

       Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); 
       //noinspection unchecked 
       Result result = doInBackground(mParams); 
       Binder.flushPendingCommands(); 
       return postResult(result); 
      } 
     }; 

     mFuture = new FutureTask<Result>(mWorker) { 
      @Override 
      protected void done() { 
       try { 
        postResultIfNotInvoked(get()); 
       } catch (InterruptedException e) { 
        android.util.Log.w(LOG_TAG, e); 
       } catch (ExecutionException e) { 
        throw new RuntimeException("An error occurred while executing doInBackground()", 
          e.getCause()); 
       } catch (CancellationException e) { 
        postResultIfNotInvoked(null); 
       } 
      } 
     }; 
    } 

我们只需要两件事情,需要被记住。

  • WorkerRunnable实际上是可赎回
  • 结果结果= doInBackground(mParams); //在后台线程中处理

所以这里是您的答案。 doInBackground将被处理,但onPostExecute可能会产生NPE,因为父母的活动已被破坏。