Ok, I have got following code from https://github.com/hongyangAndroid/Android-CircleMenu . Here, from print trace, I came to find that constructor is only invoked once, whereas run() method is recursively called till some condition.
My question is, why only run() method is recursively called from postDelayed(), why not constructor? and how variable anglePerSecond retains the value ? I want to understand it's flow. Thanks you.
//Automatic scrolling tasks
private class AutoFlingRunnable implements Runnable{
private float anglePerSecond;
public AutoFlingRunnable(float velocity){
this.anglePerSecond = velocity;
}
public void run(){
if((int)Math.abs(anglePerSecond) < 20){
isFling = false;
return;
}
isFling = true;
//anglePerSecond/30 in order to avoid rolling too fast
mStartAngle += (anglePerSecond/30);
//Gradually reduce this value
anglePerSecond /= 1.0666F;
postDelayed(this, 30);
//gradually reduce this value
requestLayout(); //re-layout views
}
}