Thursday, June 18, 2015

What is the purpose of Looper and how to use it?

What is the purpose of Looper and how to use it? - Hallo sahabat Google Android Developer Tutorial, Pada Artikel yang anda baca kali ini dengan judul What is the purpose of Looper and how to use it?, kami telah mempersiapkan artikel ini dengan baik untuk anda baca dan ambil informasi didalamnya. mudah-mudahan isi postingan yang kami tulis ini dapat anda pahami. baiklah, selamat membaca.

Judul : What is the purpose of Looper and how to use it?
link : What is the purpose of Looper and how to use it?

Baca juga


What is the purpose of Looper and how to use it?

http://stackoverflow.com/questions/7597742/what-is-the-purpose-of-looper-and-how-to-use-it



5 Answers

up vote181down voteaccepted
What is Looper?
Looper is a class which is used to execute the Messages(Runnables) in a queue. Normal threads have no such queue, e.g. simple thread does not have any queue. It executes once and after method execution finishes, the thread will not run another Message(Runnable).
Where we can use Looper class?
If someone wants to execute multiple messages(Runnables) then he should use the Looper class which is responsible for creating a queue in the thread. For example, while writing an application that downloads files from the internet, we can use Looper class to put files to be downloaded in the queue.
How it works?
There is prepare() method to prepare the Looper. Then you can use loop() method to create a message loop in the current thread and now your Looper is ready to execute the requests in the queue until you quit the loop.
Here is the code by which you can prepare the Looper.
class LooperThread extends Thread {
public Handler mHandler;

@Override
public void run() {
Looper.prepare();

mHandler
= new Handler() {
@Override
public void handleMessage(Message msg) {
// process incoming messages here
}
};

Looper.loop();
}
}


Demikianlah Artikel What is the purpose of Looper and how to use it?

Sekianlah artikel What is the purpose of Looper and how to use it? kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.

Anda sekarang membaca artikel What is the purpose of Looper and how to use it? dengan alamat link https://googleandroiddevelopertutorial.blogspot.com/2015/06/what-is-purpose-of-looper-and-how-to.html

Artikel Terkait

What is the purpose of Looper and how to use it?
4/ 5
Oleh

Berlangganan

Suka dengan artikel di atas? Silakan berlangganan gratis via email