The error message is android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
It appears to me even though I used the corrected code for this problem, but I don't know why
private void SparrowTimer() {
runOnUiThread(() -> {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
//what you want to do
SparrowAnimation();
}
}, 0, 6000);//wait 0 ms before doing the action and do it every 6000ms (6 sec)
//timer.cancel();//stop the timer
});
}
private void SparrowAnimation() {
sparrowFlyingImage.startAnimation(animationSparrow);
}