Passing Edittext to a Thread
<p>I am trying to pass a String value of EditText to a method in a thread, the method "channel.basicpublish". I have tried a number of ways in the method "basicpublish" like Edittext.gettext().tostring or declare global variables (above override) and passing them to local variables, but on the other hand I get an empty string though there is no error. I also tried bundle/intent, but nothing is working for me (gives error). The following code will be working because I am passing a plain string (Message="HelloRabbitmq"). So how I can pass a string from edittext to "basicpublish" which is in a thread? </p>

<pre><code>public class HandlerActivity extends Activity {
    /** Called when the activity is first created. */
    TextView tv;
    EditText etv;
    String QUEUE_NAME="bye";
    String EXCHANGE_NAME="logs";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv =  (TextView) findViewById(R.id.out);
        etv = (EditText) findViewById(R.id.out2);
        etv.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) &amp;&amp;
                    (keyCode == KeyEvent.KEYCODE_ENTER)) {
                  // Perform action on key press
                  Toast.makeText(HandlerActivity.this, etv.getText(), Toast.LENGTH_SHORT).show();
                   String  Kamran = etv.getText().toString();     
                   return true;
                }
                return false;
            }
        });
     final Handler handler=new Handler();
     final Runnable r=new Runnable()
     {
            public void run() 
            {
                tv.append("Hello");

            }
     };
     handler.postDelayed(r, 1000);
     Thread thread = new Thread()
     {
            @Override
            public void run() {             
                try {
                    while(true) {
                        sleep(1000);
                        ConnectionFactory factory = new ConnectionFactory();
                        factory.setHost("192.168.2.3");
                        Connection connection = factory.newConnection();
                        Channel channel = connection.createChannel();
                        channel.exchangeDeclare(EXCHANGE_NAME, "fanout", true);
                        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
                       String message = "Hello Rabbitmq";                   
                        channel.basicPublish( "logs",QUEUE_NAME, null, message.getBytes());
                        channel.close();
                        connection.close();
                        handler.postDelayed(r, 1000);
                        }
                }
                        catch (Exception e) {
                            // TODO: handle exception
                        e.printStackTrace();
                        }         
            }
     };
     thread.start();
             }

}
</code></pre>
