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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:06:59+00:00 2026-06-17T15:06:59+00:00

Ok i have a program which needs to wait until android enables wifi adapter

  • 0

Ok i have a program which needs to wait until android enables wifi adapter completely. I have this activity code and it works, but honestly i don’t think that this is proper way of waiting to some task to be finished ( in this case , android needs to enable wifi ).

public class MainActivity extends Activity implements Runnable {

ProgressDialog pd;
WifiManager wm;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    wm = (WifiManager) getSystemService(WIFI_SERVICE);

    if(!wm.isWifiEnabled()) {
    pd = ProgressDialog.show(this, "Stand by", "Doing work");

    Thread t = new Thread(this);
    t.start();
    }


}




@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);

    return true;
}






@Override
public void run() {

    wm.setWifiEnabled(true);
    while(wm.getWifiState() != 3) {

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

    }


    pd.dismiss();
    }
}

Can someone please tell me, how is the proper way of waiting a program from executing until some task is finished? So program scenario:

  1. If wifi is disabled, execute if statement ( show progress dialog and enable wifi )
  2. Show progress dialog until task is done ( in this case wifi enables completely)
  3. When wifi is enabled stop showing progress dialog

Thanks in advance!

  • 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-17T15:07:00+00:00Added an answer on June 17, 2026 at 3:07 pm

    Use AsyncTask for this. Show your progress bar in OnPreExecute() and do the loading process or something that needs time in doInBackground() and finally dismiss your progress dialog in onPostExecute().
    Here is the working sample-

    http://huuah.com/android-progress-bar-and-thread-updating/

    Hope it will help you

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

Sidebar

Related Questions

I have a program which needs to invoke a process to perform an operation
I have a program which needs to hold approximately 3000 open file descriptors in
My program needs to read csv files which may have 1,2 or 3 columns,
I have a simple program, which needs to make sure I can connect to
I have a Winform which needs to wait for about 3 - 4 hours.
I have a program which needs to behave slightly differently on Tiger than on
I have a program in which I need to store a Class object into
Just a quick question here. I have a program in which I need to
I need to make the program which have one form that contains PNG image
I have a program which creates JButtons which are then added to a JPanel

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.