为什么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上运行此代码。