0

I'm working with an AsyncTask for a listview that takes a few seconds to populate so I've not a view displaying over the top of the list before it's populated (similar to a progressBar spinner)

I start an animation in the preExec such as:

protected void onPreExecute()
   imageProgressOuter.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.pulse));
}

Then at the end in the postExec I'm wanting to fade the ImageView (imageProgressOuter) out. It's easy enough to do this with:

protected void onPostExecute(Void result) {
  imageProgressOuter.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.spinner_fadeout));
}

This works ok and fades out the animation, but on doing this the pulse notification stops from the onPreExecute. I'm wanting the pulse to still keep happening while the fade out takes place but I'm not quite sure how to have one running and then start another in parallel. I've used animation sets before but only stacking things and then starting the whole set. Is there a way to start this 2nd animation without the other stopping?

Andrew
  • 7,548
  • 7
  • 50
  • 72

2 Answers2

2

You could wrap your imageProgressOuter view in a FrameLayout, then in onPostExecute() fade the FrameLayout while continuing the first animation.

deRonbrown
  • 635
  • 7
  • 14
  • Excellent idea, simple and something I'd not thought of! – Andrew Mar 21 '14 at 01:01
  • Yes it did. I had to change a few other things around to get it working with my animation listeners (hence the slow reply). Thanks – Andrew Mar 22 '14 at 00:37
0

AsyncTask dont run in parallel by default after honeycomb.

You can use the executeOnExecutor

if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ) {
    new MyAsyncTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
    new MyAsyncTask().execute();
}

Some sources:

Community
  • 1
  • 1
Scoup
  • 1,323
  • 8
  • 11