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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:56:13+00:00 2026-05-26T12:56:13+00:00

I have called the wifi_refresh() from the menu to automatically update wifi info, however,

  • 0

I have called the wifi_refresh() from the menu to automatically update wifi info, however, in this way, there is nothing shown on the display. However, when I use the button to refresh, everything works fine. Anyone help?

    package com.wifi_info;

    import java.util.ArrayList;
    import java.util.List;
    import java.util.concurrent.ScheduledThreadPoolExecutor;
    import java.util.concurrent.TimeUnit;
    import android.app.Activity;
    import android.content.Context;
    import android.net.wifi.ScanResult;
    import android.net.wifi.WifiManager;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuInflater;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.ListView;
    import android.widget.Toast;
    import android.view.MenuItem.OnMenuItemClickListener;
    import java.util.concurrent.*;

   public class Wifi_infoActivity extends Activity {
/** Called when the activity is first created. */

int update_freq =1;
MenuItem auto_check;
MenuItem view_cg;
MenuItem view_apl;
MenuItem view_sm;
MenuItem set_1;
MenuItem set_3;
MenuItem set_5;
MenuItem set_10;
MenuItem view_menu;
MenuItem settings_menu;
int interval = 1000;
boolean checked = false;
ScheduledThreadPoolExecutor exet = new ScheduledThreadPoolExecutor(5);// not sure          about the number  
ScheduledFuture<?> handler;
Button refreshButton;

//------------------------------------wifi_refresh---------------------------------------------
WifiManager wifi;
ArrayAdapter<String> aa;
int layoutID = android.R.layout.simple_list_item_1;
ArrayList<String> wifi_info;
int result_size;
String channel;
ListView lv;
List<ScanResult> results;

//—————————————wifi_refresh———————————————

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    wifi_refresh();

    refreshButton = (Button)findViewById(R.id.refreshbutton);
    refreshButton.setOnClickListener(new OnClickListener(){
        public void onClick(View arg0){

            wifi_refresh();             
        }
    });
}

public void onStop(){
    super.onStop();
    exet.shutdownNow();
}

@Override
public boolean onCreateOptionsMenu(Menu menu){

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);

    view_menu = menu.findItem(R.id.view);
    settings_menu = menu.findItem(R.id.settings);
    auto_check=menu.findItem(R.id.set_check);
    if (checked == false)
        auto_check.setChecked(false);
    else
        auto_check.setChecked(true);
    view_cg = menu.findItem(R.id.view_cg);
    view_apl = menu.findItem(R.id.view_apl);
    view_sm = menu.findItem(R.id.view_sm);    
    set_1 = menu.findItem(R.id.set_1);
    set_3 = menu.findItem(R.id.set_3);
    set_5 = menu.findItem(R.id.set_5);
    set_10 = menu.findItem(R.id.set_10);

    view_menu.setOnMenuItemClickListener(new OnMenuItemClickListener(){
        public boolean onMenuItemClick(MenuItem item){
            return true;
        }
     });

    settings_menu.setOnMenuItemClickListener(new OnMenuItemClickListener(){
        public boolean onMenuItemClick(MenuItem item){
            return true;
        }
    });

    view_cg.setOnMenuItemClickListener(new OnMenuItemClickListener(){
        public boolean onMenuItemClick(MenuItem item){
            //show channel graph
            return true;
        }
    });

    view_apl.setOnMenuItemClickListener(new OnMenuItemClickListener(){
        public boolean onMenuItemClick(MenuItem item){
            wifi_refresh();
            return true;
        }
    });

    view_sm.setOnMenuItemClickListener(new OnMenuItemClickListener(){
        public boolean onMenuItemClick(MenuItem item){
            //show sm
            return true;
        }
    });

    auto_check.setOnMenuItemClickListener(new OnMenuItemClickListener(){
        public boolean onMenuItemClick(MenuItem item){
            if(checked==false){ 
                auto_check.setChecked(true);
                checked = true;
                set_1.setCheckable(true);
                set_3.setCheckable(true);
                set_5.setCheckable(true);
                set_10.setCheckable(true);
                showChosen();
                schedule_task();

            }else{
                auto_check.setChecked(false);
                checked = false;
                set_1.setCheckable(false);
                set_3.setCheckable(false);
                set_5.setCheckable(false);
                set_10.setCheckable(false);
            }
            return true;
        }
    });

    set_1.setOnMenuItemClickListener(new OnMenuItemClickListener(){
        public boolean onMenuItemClick(MenuItem item){
            if(checked==true){
            showChosen();
            update_freq=1;
            showChosen();
            reschedule();
            }
            return true;
        }
    });

    set_3.setOnMenuItemClickListener(new OnMenuItemClickListener(){
        public boolean onMenuItemClick(MenuItem item){
            if(checked==true){
            showChosen();
            update_freq=3;
            showChosen();
             reschedule();
            }
            return true;
        }
    });

    set_5.setOnMenuItemClickListener(new OnMenuItemClickListener(){
        public boolean onMenuItemClick(MenuItem item){
            if(checked==true){
            showChosen();
            update_freq=5;
            showChosen();
             reschedule();
            }
            return true;
        }
    });

    set_10.setOnMenuItemClickListener(new OnMenuItemClickListener(){
        public boolean onMenuItemClick(MenuItem item){
            if(checked==true){
            showChosen();
            update_freq=10;
            showChosen();
             reschedule();
            }
            return true;
        }
    });
    return true;

}

public boolean showChosen(){
    switch(update_freq){
    case(1):{
        set_1.setChecked(true);break; 
    }
    case(3):{
        set_3.setChecked(true);break;
    }
    case(5):{
        set_5.setChecked(true);break;
    }
    case(10):{
        set_10.setChecked(true);break;
    }
    }return true;
}

public void onClick(String n) {
    Toast.makeText(Wifi_infoActivity.this,n,
        Toast.LENGTH_SHORT).show();
}

public void schedule_task(){

    Runnable task = new Runnable(){ 
        public void run(){
            wifi_refresh();
     }
    };
    handler = exet.scheduleWithFixedDelay(task,0, interval, TimeUnit.MILLISECONDS);
}

public void reschedule(){
    while(interval!=(update_freq*1000)){
        handler.cancel(true);
        interval = update_freq*1000;
        handler = exet.scheduleWithFixedDelay(new Runnable(){
            public void run(){
                wifi_refresh();
            }
        }, 0, interval, TimeUnit.MILLISECONDS);
    }
}

public void wifi_refresh(){

    wifi_info = new ArrayList<String>();
    result_size =0;
    channel = "";

    lv = (ListView)findViewById (R.id.myListView);
    wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);

    if(!wifi.isWifiEnabled())
        if(wifi.getWifiState()!=WifiManager.WIFI_STATE_ENABLING)
            wifi.setWifiEnabled(true);

    wifi.startScan();
    results = wifi.getScanResults();
    result_size = results.size();

    for(int j =0;j<result_size;j++){
        String mystring = new String();
        ScanResult result = results.get(j);

        switch (result.frequency) {
        case 2412: channel = "1"; break;
        case 2417: channel = "2"; break;
        case 2422: channel = "3"; break;
        case 2427: channel = "4"; break;
        case 2432: channel = "5"; break;
        case 2437: channel = "6"; break;
        case 2442: channel = "7"; break;
        case 2447: channel = "8"; break;
        case 2452: channel = "9"; break;
        case 2457: channel = "10"; break;
        case 2462: channel = "11"; break;
        case 2467: channel = "12"; break;
        case 2472: channel = "13"; break;
        case 2484: channel = "14"; break;
        }

        mystring = String.format("SSID: %s,       Level: %s,       Authentication: %s,       BSSID: %s,        Frequency:%s MHz,     Channel:%s",  result.SSID.toString(), result.level, result.capabilities.toString(),result.BSSID.toString(), result.frequency, channel);
        wifi_info.add(j, mystring);
        channel = "";
    }    

    aa = new ArrayAdapter<String>(this,layoutID, wifi_info);
    lv.setAdapter(aa);
}

}

  • 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-26T12:56:14+00:00Added an answer on May 26, 2026 at 12:56 pm

    Make sure that the thread calling the wifirefresh method is also the UI thread . Because in Android there is only one main UI thread and the others are not non UI threads .
    Hope this helps .

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

Sidebar

Related Questions

Is there a convention for naming the private method that I have called _Add
I'm binding a gridview dynamically from a table in my database I have called
I have called a view from another with Html.Action method. I want to call
I have initialised an instance of a class i have called Relation this class
I have called a method using a secondary thread. From inside the method i
I have a .NET webmethod that I have called from jQuery. The method returns
I have a table view class called RootViewController and a class providing WiFi functionality
I have an android app that repeatedly collects fingerprints from the wifi-networks that are
I have called a function from a class to find all the items related
I have a java script function that i have called on body load mousemove()

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.