Hi to all.
I've the following problem.I have an activity with two togglebutton :
the first lets start a new thread that send messages to the main
thread who care about them trought handlemessage(), and call thhe
invalidate.
The problem is that when I click on this firrst togglebutton, the
animation starts, but when I re-click on it, I have the folloqing
messaege on Logcat. Does anybody want to help me ??? THANKS

LOGCAT ERROR when i Click on the toggle button and then reclick on
it :

06-15 15:49:11.067: DEBUG/onClick(271): Sono in onClick
06-15 15:49:11.067: DEBUG/onClick(271): pulsante OFF premuto
06-15 15:49:11.457: WARN/dalvikvm(271): threadid=7: thread exiting
with uncaught exception (group=0x4001d800)
06-15 15:49:11.467: ERROR/AndroidRuntime(271): FATAL EXCEPTION:
Thread-8
06-15 15:49:11.467: ERROR/AndroidRuntime(271):
android.util.AndroidRuntimeException: { what=6 when=56421 } This
message is already in use.
06-15 15:49:11.467: ERROR/AndroidRuntime(271):     at
android.os.MessageQueue.enqueueMessage(MessageQueue.java:171)
06-15 15:49:11.467: ERROR/AndroidRuntime(271):     at
android.os.Handler.sendMessageAtTime(Handler.java:457)
06-15 15:49:11.467: ERROR/AndroidRuntime(271):     at
android.os.Handler.sendMessageDelayed(Handler.java:430)
06-15 15:49:11.467: ERROR/AndroidRuntime(271):     at
android.os.Handler.sendMessage(Handler.java:367)
06-15 15:49:11.467: ERROR/AndroidRuntime(271):     at
it.giancarlo.tachimetro.Controller.run(Controller.java:43)
06-15 15:49:11.467: ERROR/AndroidRuntime(271):     at
java.lang.Thread.run(Thread.java:1096)
06-15 15:49:11.557: WARN/ActivityManager(59):   Force finishing
activity it.giancarlo.testtachimetro/.TestTachimetro
06-15 15:49:12.067: INFO/ARMAssembler(59): generated
scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at
[0x2c2c38:0x2c2cf4] in 3484920 ns
06-15 15:49:12.077: WARN/ActivityManager(59): Activity pause timeout
for HistoryRecord{44f59220
it.giancarlo.testtachimetro/.TestTachimetro}
06-15 15:49:22.908: WARN/ActivityManager(59): Activity destroy timeout
for HistoryRecord{44f59220
it.giancarlo.testtachimetro/.TestTachimetro}



HERE IS SAME CODE :

public class TestTachimetro extends Activity {

        Tachimeter tachimeter1=null;
        Tachimeter tachimeter2= null;
        ToggleButton togglebutton= null;
        ToggleButton togglebuttonfari= null;
        Thread thread_tachimeter1=null;
        Thread thread_tachimeter2=null;
        Thread thread_button=null;
        Message message1, message2;
        int sleep_time=1000;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("TestTachimeter","onCreate");

        setContentView(R.layout.main);
        tachimeter1 = (Tachimeter) findViewById(R.id.customView);
        tachimeter1.setimg(R.drawable.speedometer);
        tachimeter1.configure(255, 220, 260);

        tachimeter2 = (Tachimeter) findViewById(R.id.customView2);
        tachimeter2.setimg(R.drawable.contagiri);
        tachimeter2.configure(270, 222, 60);

        togglebutton = (ToggleButton)
findViewById(R.id.togglebutton); // aggiunto
        togglebuttonfari = (ToggleButton)
findViewById(R.id.togglebuttonfari); // aggiunto

    } // fine metodo onCreate

 // -------------------- onResume()
-----------------------------------
    @Override
        protected void onResume() {
                super.onResume();
                Log.d("onResume", "Sono in onResume");

                togglebutton.setOnClickListener(new OnClickListener() {
                    public void onClick(View vass) {
                        Log.d("onClick", "Sono in onClick");
                                if (togglebutton.isChecked()) {
                                        Log.d("onClick", "pulsante premuto");
                                        thread_tachimeter1=new Thread(new
Controller(handler1,handler2));
                                        thread_tachimeter1.start();

                                                }// fine run
                                        });

                                        }// fine if

                                else {

                                Log.d("onClick", "pulsante OFF premuto");
                                        Log.d("valore", "valore pari ad 1");

                                        thread_tachimeter1.interrupt();
                                        
handler1.removeCallbacksAndMessages(handler1);


                        }
                    }// fine onclick
                });// fine onclicklistner


                    togglebuttonfari.setOnClickListener(new OnClickListener() {
                            public void onClick(View vass) {
                                Log.d("onClick", "Sono in onClick");
                                // Perform action on clicks
                                if (togglebuttonfari.isChecked()) {

                                        Log.d("onClick", "togglebuttonfari 
pulsante premuto");
                                } else if (!togglebuttonfari.isChecked()) {

                                        Log.d("onClick", "togglebuttonfari 
pulsante OFF premuto");
                                } // fine else if
                            }// fine onclick
                    }); // fine OnClickListener
    } // fine onResume

//----------  L'Handler che riceve i messaggi inviati dal thread
thread_tachimeter1 ----
    Handler handler1=new Handler(){

        @Override
        public void handleMessage(Message msg){
                Log.d("handlemessage", "all'interno di handlemessage1" );
                        tachimeter1.setVelocità(msg.what);
                        tachimeter1.invalidate(); // serve per richiamare il 
metodo ondraw
che ridisegna la View;
                        //SystemClock.sleep(sleep_time);
                super.handleMessage(msg);
                this.removeCallbacksAndMessages(handler1);
                //thread_tachimeter1.notifyAll();

        } // fine metodo handleMessage



    }; // fine Handler

} // fine classe


 CLASSE CONTROLLER :

public class Controller implements Runnable {

        Message message1;
        Message message2;
        Handler handler1;
        Handler handler2;
        int sleep_time=1000;
        int x=0;
        public static int current;
        public static int valore;

        public Controller ( Handler hand1, Handler hand2) {
                handler1=hand1;
                handler2=hand2;

        } // fine costruttore

        @Override
        public void run() {
                Log.d("Controller - run", "All'interno di run");

                message1 = Message.obtain();

                message1.what= 0;

                do{

                        SystemClock.sleep(sleep_time);
                        message1.what=x + 3;
                        x=message1.what;
                        current=message1.what;
                        handler1.sendMessage(message1);

                 } while (!Thread.currentThread().isInterrupted());



                } //  fine metodo run()

}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to