我正在尝试保存各种 wifi 扫描的 BSSID 和信号强度。但是,我只关心最近的四次扫描。当它扫描四次时它工作正常,但奇怪的事情开始发生,就像每次扫描的大小(结果的数量)在大约第 6 次扫描后是相同的。这段代码有问题吗?我将结果存储在一个集合列表中(尽管在处理数据时我只保留四个最新的集合)
public class MainActivity extends Activity {
List<HashSet<Pair>> addresses = new ArrayList<HashSet<Pair>>();
List <ScanResults> results;
...
@Override
public void onCreate(Bundle savedInstanceState) {
//This whole part of the code is run once every ten seconds through use of a timer
mainWifi.startScan();
results = mainWifi.getScanResults();
int entry = addresses.size();
if (entry == 4) { // already has 4 addresses
addresses.remove(0); // remove the
// oldest
// set
entry = 3;
}
addresses.add(entry, new HashSet<Pair>());
for (int i = 0; i < results.size(); i++) {
addresses.get(entry).add(new Pair(results.get(i).BSSID,results.get(i).level));
}
}