Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android run a Task Periodically

Tags:

I want to run a method periodically in an android activity which updates a certain field after x seconds. I know it can be done in timerTask but what is the best way to do it? Code samples would be helpful.

like image 912
Sultan Saadat Avatar asked Jun 21 '11 13:06

Sultan Saadat


People also ask

Does Work Manager work when app is closed?

WorkManager is intended for work that is required to run reliably even if the user navigates off a screen, the app exits, or the device restarts.

What is a handler Android?

A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue . Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler it is bound to a Looper .

What is an android service?

An Android service is a component that is designed to do some work without a user interface. A service might download a file, play music, or apply a filter to an image. Services can also be used for interprocess communication (IPC) between Android applications.


1 Answers

You should use Handler and its postDelayed function. You can find example here: Repeat a task with a time delay?

like image 177
inazaruk Avatar answered Nov 15 '22 12:11

inazaruk