[英]Android storing multiple data
I am currently using Android Network Service Discovery.我目前正在使用 Android 网络服务发现。 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?示例 我有 3 个要存储的名称,我该如何做到这一点?
Every time you get a name just add it into a list, eg myListOfNames.每次你得到一个名字时,只需将它添加到一个列表中,例如 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.其中 TextUtils.join 将您的列表折叠成一个逗号分隔的字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.