I am trying to send some strings on my android device using bluetooth to my arduino so I am wondering if my logic is correct for my code.

The part I am stuck on how to implement if all arguements are OK then it should send String temp = "t"; continously every 5 seconds.

but is rest of my logic correct and will it work as intended?

public class SendOut implements Runnable{

        private boolean sStop = false;
        private Thread I;

        String temp = "t";

        public SendOut(){
            I = new Thread(this, "Output Thread");
            I.start();
        }

        public boolean isRunning(){
            return I.isAlive();
        }

        //button down to send data to arduino
        butDown.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                if(targetTemp != RoomTemp)
                {
                    temp = '1';
                    break;
                }
                else 
                {
                    temp = '0';
                    break;
                }
            }
        });

        //button Up to send data to arduino
        butUp.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                if(targetTemp != RoomTemp)
                {
                    temp = '1';
                    break;
                }
                else 
                {
                    temp = '0'
                    break;
                } 
            }
        });

        public void onToggleClicked(View AC) {
    // Is the toggle on?
            boolean off = ((ToggleButton) view).isChecked();

             if (on) 
                {
                    temp = 'acON';
                    break;
                }
                else 
                {
                    temp = 'acOff';
                    break;
                } 
        }

        public void onToggleClicked(View heat) {
    // Is the toggle on?
            boolean off = ((ToggleButton) view).isChecked();

             if (on) 
                {
                    temp = 'heatON';
                    break;
                }
                else 
                {
                    temp = 'heatOff';
                    break;
                } 
        }

        @Override
        public void run() {
            // TODO Auto-generated method stub
            try {
                while(true){
                    mBTSocket.getOutputStream().write(temp.getBytes());
                    Thread.sleep(5000);
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public void stop() {
            // TODO Auto-generated method stub
            sStop = true;
        }

    }

you are using some variables that I don't see declared or initialized anywhere, so I'll doubt this code 'll even compile

You shouldn't use Thread class in there. You may use Handler class instead to do the pause/sleep what you are doing - example.

Also, why there are 2 onToggleClicked() methods with exactly the same prototype? This is not a polymorphism because both have the same argument number & type. As a result the latter method will be used (name of argument means nothing).

This article has been dead for over six months. Start a new discussion instead.