I am beginner in android.
What I want: Here I am trying to achieve that sub handler should call 10 times of every second of main handler. And that main handler should continue until 20 seconds.
Issue: To check that i\I have used log but its not working. It goes into sub handler some times 8 times or some times 9 or 10. Is there any logical error or is there any other better way to achieve this? Thank you.
My code:
int i=0;
int cont;
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
i++;
cont = 1;
Log.e("main count", i + "");
final Handler handler1 = new Handler();
handler1.postDelayed(new Runnable() {
@Override
public void run() {
if (cont <= 10) {
Log.e("sub count ", cont + "");
cont++;
handler1.postDelayed(this, 100);
}
}
}, 100);
if (!(i == 20)) {
handler.postDelayed(this, 1000);
}
}
}, 1000);