我有以下代码行
intent.putExtra("connectionAddress", connectionManager.connectionAddress);
connectionAddress
实际上是InetAddress
。我无法弄清楚“get..
”的适当方法。我怀疑我需要将它转换为另一种类型并再次返回?在哪种情况下最好的方法是什么?
我需要确保我仍然拥有在下一个活动中创建DatagramSocket
所需的信息。
答案 0 :(得分:1)
您需要将intent中的地址作为可序列化的额外内容,然后将其强制转换回InetAddress
。
InetAddress address = (InetAddress)intent.getSerializableExtra("connectionAddress");