0

为什么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();
}

请注意,我在 Fragment 类的 ImageView 的 onClick 中运行此代码。

4

0 回答 0