Hi I am writing an application for Android. I use Android Studio 2.1 and Android 4.0.3. My application uses Wi-Fi data and I can not get a variable's content from outer class. I am using registerReceiver and I try to get a variable in that register receiver inner class. I'm sorry for my poor English. When I debug, I see that activityString is null. Please help. My code is here:
public class MyActivity extends Activity {
public String activityString; // Here static or not no difference. This is null
public static WifiManager wifi;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locationscreen);
wifiScanResults();
String[] dataArray = activityString.split("\\.");
// Here I got Null Referance exception. When I debug, activityString is null
}
public void wifiScanResults()
{
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context c, Intent intent) {
activityString = "Go";
}
}, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
wifi.startScan();
}
It is a private inner class. I think you can not fetch anything from it. Instead, you should do whatever you will do inside it. For example you can write your code in it.