Issue
I recently saw an example of a stopwatch app , where the developer used a handler object to update the time displayed on a TextView
. Why not use an ordinary loop that keeps on updating the text instead of using a handler?
Solution
Every app has its own special thread that runs UI objects such as View objects; this thread is called the UI Thread.
Considering your stopwatch example if you just add the loop inside your activity and keep the time going then it will block your UI thread and your app may become unresponsive. To overcome this problem and not to block the UI/Main thread we use separate threads to do such ongoing/long tasks.
So what he does is created a Handler which will do the long running task and it sends the update to UI thread to update textView when required.
Answered By - UsamaAmjad
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.