+ Reply to Thread
Results 1 to 2 of 2

Thread: Thread example

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    27

    Thread example

    I am new to android and i`d like to have a simple example about threading , can you help me ?

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    41
    Threading is the best way to repeatly doing operations like displaying a text for example.
    This is how threads can be done
    Code:
    Thread t = new Thread()
    {
        @Override
        public void run() {
    		while(true) {
    			// your code here
    			// ...
    			// ...
    			
    			// You can set an interval here
                sleep(1000);
            }
        }
    };
    t.start();
    sleep(1000); means that the operation will be done each 1 second because 1000 = 1000ms which is 1 second
    you can delete the sleep line and your operation will be done 500 times at a second but of course it will consume
    a very amount of cpu and hence battery will die sooner

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts