0

I'm trying to send data to my Thread called ToD1 which is in an inner class of my Threads class then I need to do some work to it then need it to be set back to the UI thread handler my qestion is how would I call the Handlers to send the Message data? I know about AsyncTask and will try using it later the purpose of this app is for me to learn and understand the concepts of Handlers, HandlerThread, and AsyncTask so I can use them in my programing.

Here is my code for MainActivity:

public class MainActivity extends Activity implements OnClickListener {
TextView display1;
TextView display2;
EditText cl;
Button enter;
Button tod1;
Button tod2;
Bundle d = new Bundle();
static Handler mHandler;
Message msg;
Object task;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tod1 = (Button) findViewById(R.id.display1);
    tod2 = (Button) findViewById(R.id.display2);
    enter = (Button) findViewById(R.id.Enter);
    display1 = (TextView) findViewById(R.id.Display1);
    display2 = (TextView) findViewById(R.id.Display2);
    cl = (EditText) findViewById(R.id.CL);

    mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            super.handleMessage(msg);

        }

    };

}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.Enter:
        Bundle in = new Bundle();
        String input = cl.getText().toString();
        d.putString("in", input);
        msg.setData(d);
                   // eclipes ask to resovle d1 varible type?
        d1.sendMessage(msg);
        notifyAll();
        break;
    case R.id.display1:
        break;
    case R.id.display2:
        break;
    }

}

}

Here is my Thread class:

public class Threads {

public static class ToD1 {

    Thread display1 = new Thread() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            super.run();
            Message msg = new Message();
            Bundle b = new Bundle();
            Looper.prepare();
            Handler d1 = new Handler() {

                @Override
                public void handleMessage(Message msg) {
                    // TODO Auto-generated method stub
                    super.handleMessage(msg);

                }

            };

            String output;
            b.putString("key1", "out:" + String.valueOf(output));
            msg.setData(b);
            // Send msg to UI thread handler
                                    // eclipes asked solve mHandler to varible type 
            mHandler.sendMessage(msg);
        }

    };

}

}

Dakota Miller
  • 493
  • 1
  • 4
  • 22
  • you should watch [this](http://thenewboston.org/watch.php?cat=6&number=101). It's a series on `Android` programming. This video, and the next few after teaches you about `AsyncTask`. It really would help you and it's very easy to understand. I normally wouldn't just post a link, but you are asking for a lot more than you think. Simply "giving" you the code here would be a mistake. – i_me_mine Jun 25 '13 at 17:05
  • Thank you the link I'll diffently look into it. right now I was just wondering how to call the handlers i've udated the code above with comminmented out sections to show which parts are giving me the trouble. – Dakota Miller Jun 25 '13 at 17:24

0 Answers0