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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:59:49+00:00 2026-06-09T09:59:49+00:00

I want my application to check whether mobile data is enabled This works fine

  • 0

I want my application to check whether mobile data is enabled

This works fine when you just click a button, but it does only refresh the information once after a click and not automatically in “real time”.

threadCheck = new Thread(new Runnable() {

        public void run() {
            // TODO Auto-generated method stub

                try {
                    setTextfield(isMobileDataEnabled());
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }

    });



    this.startbutton.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

            threadCheck.run();

        }

    });

Whats the best, cpu friendliest, way to make this thread “loop” ?
I tried to call isMobileDataEnabled() recursively but that ended up in an stackoverflow error.

Sincerly,
Wolfen

  • 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-09T09:59:51+00:00Added an answer on June 9, 2026 at 9:59 am

    I think your best bet would actually be the ConnectivityManager broadcast listener. It will tell you when the network is available or not available. Register for the broadcast and in the listener update your button. This way there is no loop and your CPU remains mostly idle. When the network changes, it will notify your broadcaster without any polling necessary. It’s pretty fast so I wouldn’t worry about “real time” 😉

    These should help get you started.

    http://developer.android.com/reference/android/net/ConnectivityManager.html

    http://developer.android.com/reference/android/content/BroadcastReceiver.html

    public class MyActivity extends Activity {
    
       public void onCreate(Bundle b) {
          mButton = (Button) findViewById(R.id.button);
          registerReceiver(mBroadcastReceiver, new IntentFilter(ConnectivityMananger.CONNECTIVITY_ACTION));
          .....
       }
       BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
           public void onReceive(Context context, Intent intent) {
               if (ConnectivityMananger.CONNECTIVITY_ACTION.equals(intent.getAction()) {
                     boolean connectionLost = !intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
                     mButton.setText("Network Enabled:" + ! connectionLost);
                     // or whatever else you want to callback.
                }
           }
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that passes in java.util.Date. I want to check whether this
----EDIT---- I am making an jquery mobile application. Now I want to check which
I have developed a simple application before testing it i want to check whether
I am developing an application in Cocoa. I want to constantly check whether the
I want to add virtual host for the application quickstart but this error occur,
In a java web application,I want to check whether a user who signs in
I want to check whether servers are active or not from the iphone application
I have an iphone application in which I want to check whether a string
I want to check whether my gwt application is running in hosted mode or
I want to check in my application programmatically if user shutdown/restart/logoff the computer. I

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.