Android uses a single-threaded model for UI operations, meaning all UI updates must happen on the main thread. The Looper class plays a crucial role in this model.
Looper is a part of Android's message passing framework. It's designed to keep a thread alive and to process Messages and Runnable objects from a MessageQueue.
Here's how you can use a Looper in a background thread:
class ExampleThread extends Thread {
public Handler handler;
public void run() {
Looper.prepare();
handler = new Handler();
Looper.loop();
}
}
Remember: Don't perform long-running operations on the main thread to avoid UI freezing. Use a background thread with a Looper for such tasks!
No comments:
Post a Comment