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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:39:35+00:00 2026-05-25T13:39:35+00:00

In my app, I would like to offer an action, which shall be executed

  • 0

In my app, I would like to offer an action, which shall be executed in background regularly. So I use the AlarmManager, which starts an IntentService.

The tricky part is, that this background action needs Internet connection. So I tried using a WakeLock which didn’t seem to enforce a connection, when the device was locked.

Then I thought about registering a BroadcastReceiver to listen for “android.net.conn.CONNECTIVITY_CHANGE” when the service starts and immediately unregistering it, as soon as the desired broadcast is received.

My code looks something like this:

public class BackgroundService extends IntentService {
    private static final IntentFilter filter =
        new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    private static NetworkStateChangedReceiver receiver =
        new NetworkStateChangedReceiver();

    protected void onHandleIntent(Intent intent) {
        registerReceiver(receiver, filter);
    }
}

My question is now: Will this receiver be destroyed, as soon as the service stops (as it has nothing to do, as long as no connection is available)?
And therefore, how can I realize a service, that delays it’s work until a network connection is availalbe?

Thanks.

  • 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-25T13:39:35+00:00Added an answer on May 25, 2026 at 1:39 pm

    Will this receiver be destroyed, as soon as the service stops (as it has nothing to do, as long as no connection is available)?

    Yes. It will live for a few microseconds.

    And therefore, how can I realize a service, that delays it’s work until a network connection is availalbe?

    Use ConnectivityManager and getActiveNetworkInfo(), see if there’s a connection, and if not, just exit onHandleIntent() and wait for the next alarm.

    Or, register your CONNECTIVITY_ACTION receiver in the manifest and use it to schedule and cancel your alarms, so the alarms are only active while there’s a connection.

    There are various other strategies, but those two should give you a starting point.

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

Sidebar

Related Questions

I would like to use Public/Private encryption where my web app would sign an
I have a .NET Framework 2.0 app and would like to use the Windows
I'm developing an app (an API) in python and I would like to offer
I'd like to offer my app users a couple of different skins to use
We have an AdWhirl-sponsored version of an app (Moonrise) and would like to offer
I would like to offer authenticated API access to my web app. The consumers
I am developing an app where I would like to offer users the capability
I would like to setup a multi-tenant ASP.NET MVC app. Ideally, this app would
I have an iPhone app and would like to create iPad version of it.
I have a fairly standard rails app and would like to be able 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.