Good day! Please tell me what could be the reason:

There is a service, it launches a task on a schedule (5 minutes), but the task is carried out completely horizontally. Maybe 3 times without a break be executed, maybe in three minutes, maybe in ten .. How can this be? I thought maybe they are breeding in me, brought this into the logs from the task - they are the same everywhere, it turns out that the timer is dancing as it wants? But is it possible?

It is described as:

@Override public int onStartCommand(Intent intent, int flags, int startId) { if (!iam_started) { iam_started = true; if (TT==null) { TT = new myTimerTask(); T2 = new Timer(); if (TT != null && T2 != null) T2.scheduleAtFixedRate(TT, 1000, 1000*60*5); } ... } 

Well, there I myself:

  private class myTimerTask extends TimerTask { public void run() { } } 

Is that what I'm doing wrong? ...

  • What version of android and phone screen off? - pavel
  • one
    One of the things you do wrong is that you don’t adhere to the convention on naming classes and variables in java at all. And the formatting of C ++ smacks. - s_klepcha
  • one
    @s_klepcha I do not think that this affects the execution of the code. - pavel
  • Android has services (and they are not dying, they are sitting in the background) and your application, it is just an application that will work, shut down, forget (or was thrown out of the RAM). And the service .. (I don’t remember where the good codes for this case were but give an example) developer.alexanderklimov.ru/android/theory/services-theory.php - Denis Kotlyarov
  • 2
    The style of the code, well .. who got used to what apparently, I grew up with C in due time. But, as rightly noted, this does not affect the execution of the code. - Alexander

0