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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:13:41+00:00 2026-05-22T02:13:41+00:00

I want ProgressDialog to show while my code enables WiFi and connects to a

  • 0

I want ProgressDialog to show while my code enables WiFi and connects to a particular SSID. I did see other questions with starting another thread. Is it necessary for me to start a separate thread to be able to see the ProgressDialog while the code between show() and hide() is executed? The Wifi that i connect to is known to exist and has no security key.

package com.connectionmanager.app;

import java.util.List;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class FoundSavedUser extends Activity implements OnClickListener{

    private WifiManager WifiInfo;
    private ProgressDialog dialog;
    private List<ScanResult> results;

    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.connect_to_gogo);

        //logView is temporary for displaying messages regarding connectivity.
        TextView logView = (TextView) findViewById(R.id.logTextView);

        WifiInfo = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);

        //Is WiFi on?
        if(!WifiInfo.isWifiEnabled())
        {
            //Show the acknowledgment button that will allow user to turn on WiFi.
            Button wifiButton = (Button) findViewById(R.id.wifiButton);
            wifiButton.setVisibility(View.VISIBLE);
            wifiButton.setOnClickListener(this);
        }

    }

    @Override
    public void onClick(View v) 
    {
        // TODO Auto-generated method stub

        if(v.getId() == (R.id.wifiButton))
        {
            //Setup a ProgressDialog until WiFi is switched on.
            dialog = ProgressDialog.show(FoundSavedUser.this, "", "Loading. Please wait...", true);
            dialog.show();

            //Switch on WiFi
            WifiInfo.setWifiEnabled(true);

            //Get list of the results in object format ( like an array )
            results = WifiInfo.getScanResults();
            int i = 0;
            String[] ssid = new String[results.size()];
            for (ScanResult result : results) 
            {
                ssid[i] = result.SSID;
                i++;
                Log.v("Hello","Printing result.SSID: " + result.SSID);
            }
            Log.v("Hello","Connecting to: myWiFi");

            WifiConfiguration wifiConfig = new WifiConfiguration();
            wifiConfig.SSID = "\"myWiFi\"";
            wifiConfig.priority = 1;
            wifiConfig.allowedKeyManagement.set(KeyMgmt.NONE);
            wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
            wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
            wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
            wifiConfig.status=WifiConfiguration.Status.ENABLED;
            int netId = WifiInfo.addNetwork(wifiConfig);
            if (WifiInfo.enableNetwork(netId, true))
            {
             Log.v("Hello","Connection enabled");
            }
            else
            {
             Log.v("Hello","Connection not enabled");
            }
            Log.v("Hello","Print netId: " + netId);
            Log.v("Hello","Connection success!");

            //Hide the ProgressDialog
            dialog.hide();

        }
    }
}
  • 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-22T02:13:42+00:00Added an answer on May 22, 2026 at 2:13 am

    Correct, it has to run in a separate thread.

    Take a look at this solution, Android: ProgressDialog doesn't show

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

Sidebar

Related Questions

ProgressDialog onClick not working.. here is my code .. Basically i want to show
I want to show ProgressDialog when I click on Login button and it takes
Possible Duplicate: Android: ProgressDialog.show() crashes with getApplicationContext I want to have a progress dialog
I have this code below and want it to show the progress of a
I want to have a ProgressDialog with determinate progress bar instead of default spinner.
want to show a error message as a result of a form action. For
want to know why String behaves like value type while using ==. String s1
Possible Duplicate: AsyncTask block UI threat and show progressbar with delay I want to
When calling progressDialog = ProgressDialog.show(this, null, null, true); usually the developers wants to only
I am developing an app using jquery mobile.. In that i want to show

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.