在之前或之后使用AsyncTask.execute()时,帧动画不起作用

时间:2017-07-21 12:47:11

标签: android performance android-asynctask android-thread

为什么AsyncTask会导致代码中与其无关的阻塞。例如:

动画在此代码中运行:

if(!(speakMe.getStatus() == AsyncTask.Status.RUNNING) ){
      ((AnimationDrawable) mImageView.getBackground()).start();
      Toast.makeText(getActivity(), "In the zone!", Toast.LENGTH_SHORT).show();
  //  speakMe = new SpeakQuote();
  //  speakMe.execute(quote);
}

但不是这个:

if(!(speakMe.getStatus() == AsyncTask.Status.RUNNING) ){
    ((AnimationDrawable) mImageView.getBackground()).start();
    Toast.makeText(getActivity(), "In the zone!", Toast.LENGTH_SHORT).show();
    speakMe = new SpeakQuote();
    speakMe.execute(quote);
}

或者在此:

if(!(speakMe.getStatus() == AsyncTask.Status.RUNNING) ){
    speakMe = new SpeakQuote();
    speakMe.execute(quote);
    ((AnimationDrawable) mImageView.getBackground()).start();
    Toast.makeText(getActivity(), "In the zone!", Toast.LENGTH_SHORT).show();
}

请注意,我在片段类中的ImageView上运行此代码。

0 个答案:

没有答案