When I try to animate an image from a Timer I can't do it, however the Toast is executed. The animation works correctly because I tested from a button.It is rare, only the Toast runs and does not fail the application. Someone could help me!
public class Ayuda extends Activity {
ImageView imagen_toro, imagen_vaca;
Animation rotar;
Timer timer;
TimerTask timerTask;
final Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ayuda);
imagen_toro = (ImageView) findViewById(R.id.imagen_toro_ayuda);
imagen_vaca = (ImageView) findViewById(R.id.imagen_vaca_ayuda);
rotar = AnimationUtils.loadAnimation(this, R.animator.animar_toro);
timer = new Timer();
timerTask = new TimerTask() {
public void run() {
runOnUiThread(new Runnable() {
public void run() {
rotar.reset();
imagen_toro.setAnimation(rotar);
rotar.reset();
imagen_vaca.setAnimation(rotar);
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(getApplicationContext(), "test", duration);
toast.show();
}
});
}
};
timer.schedule(timerTask, 3000, 3000); //
}
}
As a first, you should use PostDealyed instead of timer. also, you need to call start animation