Android gives the facility to develop more interactive/efficient applications with the help of Threads.
Why we use?
We use the thread when we want to do some transaction with database; Web Request etc when we want our application not hang during processing.
How to use thread in Android Application?
It’s pretty simple and straight forward. There are lots of other ways but now I using this.
Thread thread = new Thread () {
public void run () {
//Code ur action here
ThreadResult.sendEmptyMessage(0);
}
};
thread.start();
private Handler ThreadResult = new Handler() {
public void handleMessage(Message msg) {
/*
If u wants to update the GUI components during thread then use handler, GUI means Progress Bar, Label etc.
Write down here your code.
*/
}
};
Why we use Handler?
We use handler for cross-threading manipulation.
