Thread Example n ANDROID -- Timer Thread Example

Posted by Unknown Selasa, 04 Juni 2013 0 komentar
See more post on threads :
Non Runnable States in Multithreading

What is thread in java ?

This example shows how a thread get activated on every interval of time. Here an array of string is given which is used to display a text change for every activated thread calls.

public class Threadexample extends Activity {

protected int splashTime = 3000;
TextView tv1;
String[] name = {"Angel","Mark","Coding","Playground","For","All","Coderz"};
int timer =0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_threadexample);
tv1 = (TextView) findViewById(R.id.textView1);
Thread th=new Thread(){

@Override
public void run(){
try
{
for (timer = 0; timer < 7; timer++)
{
int waited = 0;
while(waited < splashTime)
{
Thread.sleep(100);
runOnUiThread(new Runnable() {
public void run() {
try {
tv1.setText(name[timer]);
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
waited += 100;
}
}
}catch (InterruptedException e) {
}

}
};
th.start();
}

}



TERIMA KASIH ATAS KUNJUNGAN SAUDARA
Judul: Thread Example n ANDROID -- Timer Thread Example
Ditulis oleh Unknown
Rating Blog 5 dari 5
Semoga artikel ini bermanfaat bagi saudara. Jika ingin mengutip, baik itu sebagian atau keseluruhan dari isi artikel ini harap menyertakan link dofollow ke http://androidpopuler.blogspot.com/2013/06/thread-example-n-android-timer-thread.html. Terima kasih sudah singgah membaca artikel ini.

0 komentar:

Posting Komentar

Trik SEO Terbaru support Online Shop Baju Wanita - Original design by Bamz | Copyright of android populer.