I want MainActivity
call a SecondActivity
and the SecondActivity
return a List of Strings.
Every answer that I have read explains how to pass data from MainActivity
to SecondActivity
.
I have created an Activity that calculate all possible IPs in internal network and keep them to a List.
I want to pass this List to MainActivity
.
Could you suggest me some links or code to solve my problem?
I am totally new at Android Studio but I have to do it.
Here the snippet code from MainActivity
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean check_conn = false;
check_conn = checkInternetConnection();//check if you are on internet
if (check_conn){
//we have connection
// find the all the possible IPs
Intent intent = new Intent(MainActivity.this, rangeIP_test.class);
startActivity(intent);
}
else {
// do something annoying
Toast.makeText(MainActivity.this,
"We need Internet Connection!", Toast.LENGTH_LONG).show();
}
}
});
The rangeIP_test Activity that calculate IPs
WifiManager my_wifi = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
String subnet = getSubnetAddress(my_wifi.getDhcpInfo().gateway);
IPs = findIP(subnet);
public List<String> findIP(String subnet){
List<String> all_IPs;// All IPs on network
all_IPs = new ArrayList<>();
for (int i=2; i<255; i++){
String host = subnet + "." + i;
all_IPs.add(host);
}
return all_IPs;
}