C
C
Chvalov2015-08-28 11:12:55
Java
Chvalov, 2015-08-28 11:12:55

How to make an eternal loop with processing every 100 milliseconds (Android)?

It is necessary after starting the program every 100 - 200 milliseconds to interrogate the device and receive a response.
How to write such a loop that processes everything that is in it every 100 - 200 milliseconds?
P.S. The millisecond value must be stored in an int variable

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evhen, 2015-08-28
@EugeneP2

You can use the standard Java timer

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class App 
{
    public static void main( String[] args )
    {

    	Timer timer = new Timer();
    	timer.schedule(new TimerTask() {
      @Override
      public void run() {
        System.out.println("Hello");
      }
    }, new Date(), 100);
    }
}

O
one pavel, 2015-08-28
@onepavel

habrahabr.ru/post/116363
your choice ScheduledExecutorService

I
IdeSade, 2015-08-28
@IdeSade

And then we ask why Android is so voracious... )))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question