tags:

views:

41

answers:

1
Thread thred = new Thread();
        thred.run();


    public void run() {
        while (true)
        {

       try {
                Thread.sleep(500);
                Toast toast = Toast.makeText(getApplicationContext(), "Sleep Over", 100);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                Toast toast = Toast.makeText(getApplicationContext(), "Sleep NOT Over", 100);
            }
        }

This code don't work

A: 
Thread thred = new Thread()
{ 


    public void run() {
        while (true)
        {

         try {
                sleep(500);
                Toast toast = Toast.makeText(getApplicationContext(), "Sleep Over", 100);
             } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                Toast toast = Toast.makeText(getApplicationContext(), "Sleep NOT Over", 100);
             }
        }
    }
};
thred.start();

You need to call the sleep method of the current thread Thread.sleep will call the static sleep method. You need to make sure you are overriding the run method of the thread class with your own run method and then calling thread.start not run.

marme
here is my real source code http://codeviewer.org/view/code:12c6
hanswurst
it dont work....
hanswurst