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 8873399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:27:21+00:00 2026-06-14T18:27:21+00:00

Well this question is basicly similiar to what i ask, i tried to use

  • 0

Well this question is basicly similiar to what i ask, i tried to use a Timer on a Service that runs a runnable every 1 second that this runnable updates some UI in some other Activity.

This activity can be on background or dead, but the service must not stop counting down, as the guy in the added question said, I too sometimes get all the runnables run at once when i wake my phone up.

The Answer he got was Use AlarmManager, but Android docs discourages the use of AlarmManager for timeouts and ticks, and suggested using a handler, So anybody got an exemple of how its done correctly using handler?

Note that the problems begin to accure when the Phone goes to sleep and only after a while, Timer works good for like 30 mins, but for few hours it doesnt…

  • 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-06-14T18:27:23+00:00Added an answer on June 14, 2026 at 6:27 pm

    A few concepts …

    Sleep mode

    The Android kernel will go into sleep mode (by default), if no user interaction or WAKE_LOCK are request. This is done to minimized battery utilization, and means that any code will stop running.

    Alarm Manager

    This is an API that can set a timmer event to awake kernel and start running code. If an application needs to perform some long activity, it should request a wake lick, otherwise the kernel will go again into sleep mode in a short period of time.

    Whats going on with your application

    Your service is stopped as soon as the device goes into sleep. When the device is awaked by the user or by some alarm manager request made by some other application in your phone, your service starts again. When phone goes into sleep again, so goes your service.

    What you should do

    First of all, you should think carefully if you really need to have the update going on when the phone is not being used for some time (when it should be put into sleep mode). Maybe no one is using it, and having the service running continously, will keep drainning battery.

    If you don’t need the service to run continously, you have 2 options:

    Use Alarm Manager

    To wakeup the device at fixed interval times (use the less frequency possible) and update you service work. If this takes some time, request a WAKE_LOCK and release it after completion.

    Use Last

    If you can wait for the phone to be awaked by the user to update you service work is even better. Just drop all update request with exception of last one.

    Finally

    If you really need the service to run continously, request a WAKE_LOCK when service starts. Just don’t forget that you will pay that in battery live.

    Note: Dosen’t matter if you use a Timer, Handler or anything else, the above will always apply.

    Regards.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well, I tried to ask this question as a comment on this question, but
I know very well that this question is ask many time but some how
First, I don't know where to ask this question. Well this is programming QA
I hope this question isn't too general. Well, the situation is that I am
I have a situation that is well explained in this question: Range intersection /
Well this question and this question are similar but no answers that work. In
Well this is a simple question i want to filter two elements sorted reverse
I believe this question applies equally well to C# as to Java, because both
I know this question may well be the silliest question you've heard today, but
Well, first of all sorry about this question it must be pretty straight forward

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.