How and where is better to execute a periodic code on Android

338 Views Asked by At

Hi everyone (i'm a newbie in android and kotlin), What i need to do is send periodically (every 10 sec) some information, of may application, on a remote server whit a POST request independently if the application is in foreground or background. Now i found some interesting source like this: https://guides.codepath.com/android/Repeatinag-Periodic-Tasks#alarmmanager.

But i have some perplexity:

  • how would you structure this task?
  • is a bad idea to start aThreadPool on an application class?
  • is better to use a Thread or service?

Thanks everyone in advance!

More Info:

The information in question are logs, so every 10 sec the app send it's logs(if present) to a logstash -> Elasticsearch.

I know that 10 sec is a lot, and it will drain the battery of the device, but i'm not the one in charge of this decision and i can't change it.

0

There are 0 best solutions below