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

  • Home
  • SEARCH
  • 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 8040979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:04:09+00:00 2026-06-05T04:04:09+00:00

I am writing an Android service which is executed every 15 minutes. It requires

  • 0

I am writing an Android service which is executed every 15 minutes.

It requires an internet connection because it sends a request to a server and if the response of the server is like “ok” the service executes some code.

All works fine if the phone is not in standby (the screen is on), but if the phone is in standby mode the connection is unavailable and the service does not work correctly.
I want the service to wait for an available connection and then send the request to a server.

For example the phone is in standby mode and 15 minutes afterwards, the service starts and then tries to send the request to a server but the connection is unavailable. In this case I want the service to wait for a connection to become available and then send the request to server.

Can somebody suggest what it should do?

Ok but I never use alarm manager and broadcast receiver please con you post an example? but alarm manager and broadcast receiver work if phone is in standby? I write write an error I must execute the service every two hours not 15 minutes.

  • 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-05T04:04:11+00:00Added an answer on June 5, 2026 at 4:04 am

    When phone goes in standby, cpu will stop to work, causing all processes to stop their execution.
    You can avoid this by using PowerManager and lock the cpu to assure that it will stay on even when phone goes in standby:

    m_wakeLock = m_powerManager.newWakeLock(
                    PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
    
    m_wakeLock.acquire();
    ... cpu is assured to be on during this time ...
    m_wakeLock.release();
    

    But since your need is to have service to wake up every 15 min, even when in standby, this could cause an hard use of battery.
    You can avoid this by using an AlarmManager, that will schedule an event every 15 minutes, and then launch the appropriate BroadcastReceiver.
    In the BroadcastReceiver you simply send to your service a message through intent (launching service with parameter in intent), acquire cpu, do work, and release cpu.

    ————————– UPDATE ————————-

    First of all, declare your broadcastReceiver in your manifest:

    <receiver
            android:name="StartUpReceiver"
            <intent-filter>
                 <action android:name="my.Package.MyEvent" />
                 <category android:name="android.intent.category.HOME" />
             </intent-filter>
    </receiver>
    

    Your BroadcastReceiver will look look similar to this:

    public class StartUpReceiver extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
            Intent serviceIntent = new Intent();
            serviceIntent.setAction("my.Package.MyService");
            context.startService(serviceIntent);
    
        }
    
    }
    

    In this way, every time an intent with action “my.Package.MyEvent” is launched using, for example, sendBroadcast(Intent) method (CHECK HERE), your broadcast receiver (namely, just a class that extends the BroadcastReceiver class CHECK HERE) will execute it’s onReceive() method.
    In my code, i simply create an Intent with an appropriate action (“my.Package.MyService”), and then launch MyService.

    AlarmManager class simply provide you a way to schedule some intent to be launched in the future, similarly to sendBroadcast() method (CHECK HERE).
    Cpu will stay on during all execution of the onReceive() method associated to the AlarmManager. You need then to lock the cpu, launch the service which is now sure tu be executed. In the mean time onReceive() method will stop, but your service is assured to be in execution.
    The only thing you need to do is just to find a workaround on how to let your service communicate with your AlarmManager, to release the cpu lock after the service is executed, as stated in the main page of AlarmManager.
    That is, you just need to syncronize your service with your broadcast receiver, using an external object to save the information needed (in this case, if cpu is locked at the end of service release the cpu).

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

Sidebar

Related Questions

I am writing an Android application which establishes a semi-permanent TCP socket connection, i.e.
I'm novice in android. I'm writing an android application which requires the data like
I am writing an Android alarm application that uses a Service in order to
I am writing a service application in Android . In this application, I am
I am writing an Android application which can enable and disable the Network Data
I am writing an Android application which uses several 3D models. Such a model
I'm writing an Android app which will be making use of the cloud-2-device messaging
I'm writing application which consists of server side on Google App Engine (Java) and
I'm writing a simple music player, and I've created a playback service which implements
I'm writing JUnit test code for an android service implementation, and I have to

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.