0

Why is AsyncTask here causing obstruction in code which is not related to it. For example:

Animation runs in this code:

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);
}

But not in this:

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);
}

Or in this:

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

Note that I am running this code inside onClick of an ImageView in my Fragment Class.

  • Is it just the animation that doesn't run or is the thread blocked? And just to cross that out, you're talking about the first time, the ImageView is clicked, right? – k0bin Jul 21 '17 at 14:53
  • @k0bin Thread is working but animation doesn't run. Yeah when the image is clicked asynctask works it use text to speech engine to speak some text which takes like 5,6 seconds. –  Jul 21 '17 at 19:06
  • You didn't answer my second question. If the animation runs the first time you click the ImageView but not the times after that, then the if is obviously the problem. If not, I'd probably need more code (the AsyncTask would be a start). – k0bin Aug 03 '17 at 11:07

0 Answers0