I have a class that send a message by socket and I want that the message, it's the text that the user put in the plain text that it's supposed to send. So I try to catch the message of the plain text in the class but it didn't work if someone knows how to import a variable of the main class to another class.
this is the code where I execute the class
class client extends AsyncTask<String, Void, Void> {
Handler handler = new Handler( );
protected Void doInBackground(String... h) {
TextView t3;
final EditText send;
send = (EditText) findViewById( R.id.editText );
t3 = (TextView) findViewById( R.id.textView );
try {
handler.post( new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),"start client", Toast.LENGTH_LONG).show();
}
} );
WifiManager manager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
ip = Formatter.formatIpAddress(manager.getConnectionInfo().getIpAddress());
String[] mess = h;
String messag_send=(mess+"<ip>"+ip);
sock = new Socket( "192.168.5.178", 5000 );
printWriter = new PrintWriter( sock.getOutputStream() );
printWriter.write(messag_send);
String line = "no";
printWriter.flush();
printWriter.close();
sock.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
and to import
client client = new client();
client.execute(h);