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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:54:56+00:00 2026-05-31T04:54:56+00:00

I’m currently working on an application that needs to change certain settings on the

  • 0

I’m currently working on an application that needs to change certain settings on the phone such as volume when a certain event is triggered, such as a time event (between 9am and 5pm) or a battery event (battery below 30%).

The first way I thought to do this was to set up a background service which checks system time and battery level (for example) every so many seconds or minutes, then changes the phones settings when the appropriate time or battery level is met. I’m not entirely certain how to do this and I have seen some other methods which seem possible.

What would be the best method to use to perform these background checks and change settings based on the findings without requiring interaction from the user?

Thanks in advance.

[EDIT]

After being told by Jakar and gobernador to use AlarmManager, BroadcastReceiver and IntentService I came across this answer:

android: running a background task using AlarmManager

Which explained with examples how to accomplish this, thanks for the helps guys!

[EDIT]

I managed to set it up and get the service working, it doesn’t do anything yet but the rest should be easy. I did it with the following components:

  • Boot BroadcastReceiver which sets a repeating alarm to run my alarm BroadcastReceiver. This will start the service after the phone is rebooted.
  • Similar code in my main application activity that cancels any other pending intents to start the service. This starts the service when the application is run, good for starting after installation.
  • Alarm BroadcastReceiver class which has code to startService().
  • Finally my IntentService class which has the stuff I want to do in the onHandleIntent() method. (I also want to add I had a problem with this class, it was because the constructor wasn’t allowed any parameters).

Thanks again.

  • 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-31T04:54:58+00:00Added an answer on May 31, 2026 at 4:54 am

    You can check battery level in a service. I guess I would recommend enabling everything (except the battery), then see how long it takes to check/set all of what your app is suppose to. If it is under 50ms, then use a BroadcastReceiver in any case where battery level is not a concern (for example, time triggers).

    Then if user enables battery level check, then always use the service.

    If running all the checking/setting system settings takes over 50ms, then always use a Service.

    I would recommend registering a BroadcastReceiver with the BOOT_COMPLETED action, so your app will be able to run after a reboot. Also, I do not recommend running a service constantly. I would recommend using AlarmManager to run the service every 10 minutes or so. Reason being, if your service takes 15 seconds to do what it needs, then it will waste battery for it to keep running all the time.

    Also, if you are going to use a mix of Service/BroadcastReceiver, I would recommend creating a class (call it M for methods). Then in M you will have a method (say doSomething()) to do whatever you need. Then in the Service or Receiver, you would just need to call M.doSomething() so you don’t have to change the code twice for every one time you change it.

    Let me know if I was unclear/confusing or I need to add anything, and I’ll do my best to elaborate.

    EDIT:
    You would need to use AlarmManager to set the alarms, Calendar to get and set specific times/dates. https://stackoverflow.com/a/7342724/802469 will help you with this process. To keep the device’s CPU awake and keep it from stopping your service, you would need to use PowerManager. For other things that you haven’t specified, you should be able to find by Googling or by looking in the docs. WifiManager for changing wifi setting.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I have a French site that I want to parse, but am running into

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.