I am currently using Android Network Service Discovery. With the function below, each time it runs, it returns one host name. However, I want to store all data somewhere to pass to the next activity, how will I be able to that?
public void onServiceFound(NsdServiceInfo service) {
Log.d(TAG, "Service discovery success" + service.getServiceName());
if (!service.getServiceType().equals(SERVICE_TYPE)) {
Log.d(TAG, "Unknown Service Type: " + service.getServiceType());
} else if (service.getServiceName().equals(mServiceName)) {
Log.d(TAG, "Same machine: " + mServiceName);
} else if (service.getServiceName().contains(mServiceName)){
mNsdManager.resolveService(service, mResolveListener);
}
}
Example I have 3 names to store, how would I be able to do that?
Every time you get a name just add it into a list, eg myListOfNames.
just before spawning a new activity, add that list into your intent as an extra.
you can do something like this
Intent i = new Intent()
i.putExtra("my_names", TextUtils.join(",", myListOfNames));
startActivity(i);
where TextUtils.join will collapse your list into a single comma separated string.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.