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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:34:41+00:00 2026-05-13T20:34:41+00:00

I am doing a Battery Consuming research on the Android phone. I want to

  • 0

I am doing a Battery Consuming research on the Android phone. I want to run a Battery Check every 10 min till the battery totally dies. I have been having problems to make it work.

At my first try, I use a timer in a service class, and schedule the battery check every 10 mins. But soon I found that the service got paused when the screen goes off.

Then I try to use AlarmService, I use a alarm call to wake my service every 10 mins and to check the battery level and save the data to a file on the sdcard. It works with the screen off. However, I only got data of 9 hours…it seems that the AlarmService stop at some point after several hours. I don’t know why it is like this, has the system killed it for memory issues?

So my question is, has anyone written some service to run (like forever) in the background before? How do you do it and I’d appreciate very much for a sample code?

I am currently reading some posts saying that there’s a partial wake lock I can use to keep the service alive.. is this the correct way to do it?

Thanks a lot and I hope I can get some useful answers here.

  • 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-13T20:34:42+00:00Added an answer on May 13, 2026 at 8:34 pm

    At my first try, I use a timer in a
    service class, and schedule the
    battery check every 10 mins. But soon
    I found that the service got paused
    when the screen goes off.

    You probably did not hold a WakeLock, so the device fell asleep.

    it seems that the AlarmService stop at
    some point after several hours

    I rather doubt it.

    So my question is, has anyone written
    some service to run (like forever) in
    the background before?

    It is not possible to create a service that will run forever. It should be possible to create a scheduled task via AlarmManager that will be invoked “forever”.

    I am currently reading some posts
    saying that there’s a partial wake
    lock I can use to keep the service
    alive.. is this the correct way to do
    it?

    I’m not sure what “it” is. But, if you want to keep the device awake — whether for your first approach or just while you are doing work triggered by an AlarmManager — you need to hold a WakeLock.

    Here is a project that does almost exactly what you describe for the AlarmManager, minus checking the battery level, but using a WakefulIntentService to ensure the device stays awake. If you cannot get this code to run until the battery shuts down, join the cw-android Google Group and report your findings, and I’ll take a look at it.

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

Sidebar

Related Questions

I'm doing an app and I want to check on internet some information, but
Doing some jquery animation. I have certain divs set up with an attribute of
im doing parsing and the kind of text that i want to match and
I am trying to override the trust manager in Android. I want to let
I am trying to find the battery level after running an android app. When
I have the tables PRODUCTS and LISTINGS . When doing the following query: SELECT
I'm working on a project where I track the position of the phone every
I am a New B to Android. I have been Able to get the
So I have an application and I want to keep it working even if
I have the need to send and take something from a server in Android

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.