Android : Starting the ValueAnimator outside the UI Thread

on Thursday, July 10, 2014


I am trying to run android.animation.ValueAnimator from a separate thread from the UI thread. As I understand it, ValueAnimator can only be ran from the UI thread. Is there a proper way to start it from another thread to run on the UIThread?


I wrapped the ValueAnimator in an other class which holds a switch for the UI thread to periodically check.



private ArrayList<Animation> animators;
public void onResume(){
while(true)
{
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
checkAnimations();

}
}
public void checkAnimations()
{
for(Animation va: animators)
{
if(va.animationHasStarted())
va.actuallyStartTheAnimation();
}
}
public void RegisterAnimation(Animation valueAnimator)
{
animators.add(valueAnimator);
}


The infinite loop causes the UI to stall. Do you know of a better implementation/design pattern.


0 comments:

Post a Comment