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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:59:38+00:00 2026-05-24T18:59:38+00:00

In the android application that I’m designing, my service only needs to be running

  • 0

In the android application that I’m designing, my service only needs to be running when the device is connected to the router (via WiFi obviously).
I’m really new to android, and what I’ve got so far has taken me forever to Achieve, so I’m really hoping for some pointers.

My service is set to start up when the phone starts up. Also when the Activity is launched it checks whether the service is running – and if not it starts it.
I’m just wondering what code I can put into my service to make it turn off if the WiFi state is lost – and what code I need to make the service start once a WiFi connection becomes active?

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-24T18:59:41+00:00Added an answer on May 24, 2026 at 6:59 pm

    You can create a BroadcastReceiver that handles wifi connection changes.

    To be more precise, you will want to create a class – say NetWatcher:

    public class NetWatcher extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            //here, check that the network connection is available. If yes, start your service. If not, stop your service.
           ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
           NetworkInfo info = cm.getActiveNetworkInfo();
           if (info != null) {
               if (info.isConnected()) {
                   //start service
                   Intent intent = new Intent(context, MyService.class);
                   context.startService(intent);
               }
               else {
                   //stop service
                   Intent intent = new Intent(context, MyService.class);
                   context.stopService(intent);
               }
           }
        }
    }
    

    (changing MyService to the name of your service).

    Also, in your AndroidManifest, you need to add the following lines:

    <receiver android:name="com.example.android.NetWatcher">
         <intent-filter>
              <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
         </intent-filter>
    </receiver>
    

    (changing com.example.android to the name of your package).

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

Sidebar

Related Questions

I have a Web Service and an Android application that uses this web service.
I have an android application that starts an activity and is running well. I
I am making an android application that needs to use a ListView . I
I am making an android application that needs to add items to a dynamic
I am making an android application that needs to display all of the items
Im writing an Android application that needs to access data stored in a mongodb
I'm writing an Android application that needs to store dates and time into file
I have an android application that needs to store a single piece of information
I have an android application that I want to always be running in landscape
I'm writing an Android application that I want to be able to send requests

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.