Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6119931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:36:35+00:00 2026-05-23T15:36:35+00:00

I’m writing an Android app that schedules certain methods to fire at irregular intervals.

  • 0

I’m writing an Android app that schedules certain methods to fire at irregular intervals. As far as I know, there are at least two ways to do this:

  1. use Handler.postDelayed to execute a Runnable after a given time.

  2. use a Timer to schedule and execute a TimerTask after a given time.

I’m looking for a solution that can handle multiple events firing in quick succession. Which is the best method to use? Is there a better one I’m missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:36:36+00:00Added an answer on May 23, 2026 at 3:36 pm

    Short answer

    The differ in how they work in the background, using the wrong one can have dire consequences.

    All messages and runnables sent to a handler is run on the same thread as the one that created the handler, often a service or activity thread.

    Timer on the other hand spawns a new thread.

    Sounds to me like Timer is the way to go for you but it is impossible to say for sure with the information given.
    It all boils down to if you want everything to be run on one thread or multiple threads, both has it’s advantages and disadvantages.

    Long answer

    Handlers

    From the Handler documentation:

    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 the thread / message queue of the thread that is creating it — from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue.

    This means that only one event can be handled simultaneously with the handler and all other messages/runnables need to wait while another one is executing.
    Handler is however the only way to go if you want to manipulate the UI as only the main UI thread is allowed to do so.

    Using handlers can result in your application freezing if you don’t take care.
    A common mistake is when people create a handler on the main UI thread, spawn a bunch of worker threads and call heavy methods using handlers, this will cause the main UI thread to lock up and will make the dreaded “The application is not responding” dialog in android

    That said handlers can be great for dealing with thread safety, you can make every thread have a handler which handles all cross thread calls (using messages) and if you make sure only the handler modifies an object you will never have threading issues.

    Timers

    With timers however you get the overhead or creating threads and the added complexity of threading, be careful when modifying shared objects!

    The advantage is concurrency, if multiple tasks needs to be run simultaneously (or in very short interval) handlers might not be able to handle it whereas timers will.

    Other options

    • You might be able to use DelayQueue
    • If you want to allow the phone to sleep and have longer delays use AlarmManager
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.