Good morning everyone. I want to find a way to make a java code snippet repeat endlessly in android, I need to implement it in a service, but I don't want to restart the service again just a part of the code of that service (The service implementer class is IntentService) . My current code or the one that fails is a small for() loop of addition and return to 0. I show you:
for(int a=0;a<30;a++){
//Aqui va el codigo que se ejecuta
//Aqui devuelvo el valor 0 a "a" para que reinicie el proceso
a=0
}
But the problem I got is that in android the operation did not advance if the application was paralyzed, as if the code was executed in a way that did not let the rest run. If you see where I fail or know of another method, please let me know.
If your completion is to do an infinite loop you'd better do it like this:
Since the condition will always be true you will never get out of this loop.
Java
You can use a
for
:a
while
:But I prefer to use a
Handler
.or a
TimerTask
In the case of Android, you have to be careful not to block the UI by performing operations on the main thread.