Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Repetitive Task

Tags:

android

In an Activity, I need to call a web service every 30 seconds or so, and use the data to update the UI.

Is there a recommended approach on how to schedule a repetitive task?

Thanks

like image 890
Steve Avatar asked Mar 25 '10 16:03

Steve


People also ask

How can you perform repeated tasks in a service in Android?

There are at least four ways to run periodic tasks: Handler - Execute a Runnable task on the UIThread after an optional delay. ScheduledThreadPoolExecutor - Execute periodic tasks with a background thread pool. AlarmManager - Execute any periodic task in the background as a service.

Can I make Google Tasks recurring?

To set tasks to repeat from Google Tasks:Next to “Date/time,” click Repeat . Under “Repeats every,” select day, week, month, or year. Under “Ends,” select an option to create a recurring task: With no end date, select Never.

How do you call every 10 seconds on Android?

This example demonstrates how do I run a method every 10 seconds in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

What are repeated tasks?

Recurring tasks are tasks that happen over and over again, on a regular basis. For instance, as a project manager, it's common to have regularly scheduled reporting intervals.


2 Answers

If this is in a running activity, you could use Timer/TimerTask and a Handler, or you could use postDelayed() and an AsyncTask.

like image 55
CommonsWare Avatar answered Oct 20 '22 20:10

CommonsWare


You will want to create a Handler. Here is a brief code example.

like image 22
newdayrising Avatar answered Oct 20 '22 19:10

newdayrising