In android, assuming that the first time I run my app, I want to have a block of code that runs (theoretically) forever assuming that the activity is always visible, should I just do the following:
public void onResume(){
// Block of code
}
or
public void onResume(){
while(true){
// Block of code
}
}
Another way of asking this would be: In the first case, can I assume that once that block of code finishes running, that Android will re-run it again ? I tried looking for an answer for this but couldn't find any.
Thanks.
onResume
runs when the activity is made visible,if you write and infinite loop inside on resume the the application will stop responding. If you have to run some code forever you should do it as a service. whatever you have to do an infinite loop is not the right way.