0

recently, When clicking the button WI-FI connect.

but I want during connecting , showing progress dialog

How can I do ?

protected final ScanResult mScanResult;
 private OnClickListener mConnectOnClick = new OnClickListener() {
 @Override
    public void onClick(View v) {
 final WifiConfiguration config = Wifi.getWifiConfiguration(mWifiManager, mScanResult, mScanResultSecurity);
        boolean connResult = false;

if (config != null) {
       connResult = Wifi.connectToConfiguredNetwork(mFloating, mWifiManager, config, false);
    // I Think this part progress dialog. 
 }
        if (!connResult) {
            Toast.makeText(mFloating, R.string.toastFailed, Toast.LENGTH_LONG).show();
        }

        mFloating.finish();

if finish connect wifi, I want stop progress dialog
thanks.

1 Answers1

0

For this you can use async task

 class WIFIConfigurationTask extends AsyncTask<String, Void, Boolean> {
            ProgressDialog dialog;
           protected final ScanResult mScanResult;



            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                dialog = new ProgressDialog(Your_Activity.this);
                dialog.setCancelable(false);
                dialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
                dialog.setMessage(Constant.KEY_PLEASE_WAIT);
                dialog.show();
            }




            @Override
            protected Boolean doInBackground(String... params) {
               //Background Task
            }

            @Override
            protected void onPostExecute(Boolean response) {
                try {
                    super.onPostExecute(response);
                    if (isCancelled())
                        return;

                    dialog.dismiss();
     private OnClickListener mConnectOnClick = new OnClickListener() {
 @Override
    public void onClick(View v) {
 final WifiConfiguration config = Wifi.getWifiConfiguration(mWifiManager, mScanResult, mScanResultSecurity);
        boolean connResult = false;

if (config != null) {
       connResult = Wifi.connectToConfiguredNetwork(mFloating, mWifiManager, config, false);
    // I Think this part progress dialog. 
 }
        if (!connResult) {
            Toast.makeText(mFloating, R.string.toastFailed, Toast.LENGTH_LONG).show();
        }

        mFloating.finish();
                   }
        }

May it work.(Not Tested)

  • thanks this command. dialog = new ProgressDialog(Your_Activity.this); this part (your_activity) –  Mar 21 '16 at 07:00
  • How i code (your_activity) ? this class is extends BaseContent –  Mar 21 '16 at 07:01
  • You can put your class name over here or public ProgressDialog (Context context), provide the context of the class –  Mar 21 '16 at 07:04
  • 1
    your_activity is the current activity in which you want to display progress dialog or use getApplicationContext() but i suggest to use activity – Jayman Jani Mar 21 '16 at 07:05
  • I'm android beginner . perhaps, in doInBackground what write codE? –  Mar 21 '16 at 07:12
  • Use this....to understand http://developer.android.com/reference/android/os/AsyncTask.html –  Mar 21 '16 at 07:16
  • there is 3 main method of async task 1)on preexecute you have to show process what you want to show user befor task done in Postexecute you have to show after process task done just like show TOAST "suceessful download" or any think in doinbackground you have to done main logicpart of your class just go on google search for it . – Jayman Jani Mar 21 '16 at 07:28
  • I keep trying, sorry –  Mar 22 '16 at 00:44
  • @hyunwook cho What is Problem now?? – Jayman Jani Mar 22 '16 at 06:30
  • @JaymanJani thanks recently my problem http://stackoverflow.com/questions/36148043/how-catch-context-error-on-android?noredirect=1#comment59933646_36148043 –  Mar 22 '16 at 07:04
  • @hyunwookcho study this one help you http://stackoverflow.com/questions/22966601/what-is-different-between-mainactivity-this-vs-getapplicationcontext – Jayman Jani Mar 22 '16 at 10:47