我可以将字符串值传递给 Asynctask,但我无法传递数组。
谁能告诉我,我该怎么做?
我想将该数组传递给服务器 (//printwriter.write(messsages); ) ...我该如何传递?
{
String[] trymessage = new String[3];
for(int x=0;x<3;x++)
{
trymessage[x]= Integer.toString(x);
}
new Asynctask1().execute(trymesssage);
}
public class Asynctask1 extends AsyncTask<String, Void, Void> {
private PrintWriter printwriter;
protected Void doInBackground(String... messages) {
final String IP_ADDRESS = "192.168.0.4";
final int DEST_PORT = 4444;
try {
Socket client = new Socket(IP_ADDRESS, DEST_PORT); // connect to server
printwriter = new PrintWriter(client.getOutputStream(), true);
printwriter.write(messsages); // write the message to output stream
printwriter.flush();
printwriter.close();
client.close();
}
}
else{}
return null;
}
}
我想将 Asynctask1 参数更改为 String、void、String[]。但没有有效的结果。