这个WifiAdmin类在创建的时候把Context传给了它,并给这个Context注册了一个BroadcastReceiver用来监听某个广播,代码如下:
public WifiAdmin(Context context) {
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mWifiInfo = mWifiManager.getConnectionInfo();
IntentFilter filter = new IntentFilter();
filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
mReceiver = new ScanNotificationBroadcastReceiver();
context.registerReceiver(mReceiver, filter);
mContext = context;
}
然后我想要做的是:当这个BroadcastReceiver接收到广播的时候,调用它所在Activity的getResults(),我写的代码如下:
class ScanNotificationBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String strAction = intent.getAction();
if(strAction != null && strAction.equalsIgnoreCase(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)){
mWifiList = mWifiManager.getScanResults();
mWifiConfiguration = mWifiManager.getConfiguredNetworks();
((WizardBaseActivity)mContext).getResults();
}
}
}
现在问题来了,运行到((WizardBaseActivity)mContext).getResults()这句时程序报错:Error Receiving Broadcast Intent。求教怎么改啊?
------解决思路----------------------
这个WifiAdmin方法传入的context是什么?错误的LOG贴出来给大家看看。研究研究,
------解决思路----------------------
广播和页面是不能通过楼主所说的办法建立所属关系的, 如果能够这样那页面关闭后又该出现别的问题了.
有个办法可以解决,就是把广播类代码放到页面中,广播中收到消息后就仍可以使用 WizardBaseActivity.this