I am using Asyn Task to do some work in the background and then i am updating the UI using onProgressUpdate().The problem is that it is not being called one to one,means if i call it at this moment itself before the execution of the very next line of code,sometimes it is getting called and completes its work,but sometimes it completes its work after some delay.I want to know that can we make it sure that the onProgressUpdate() must execute when we want it to or it depends on the cpu of the device as when to execute the onProgressUpdate(),instantly or after some delay.Please help me.Thanks in advance.
I am using Asyn Task to do some work in the background and then
Share
When you call
onProgressUpdate(), in reality you are posting a request to an handler to have a peace of code run in another Thread.It’s up to Android OS to decide when is the best timming to switch threads, and only then you code will run.
You can somehow force a
Threadswitch, by requesting current thread to pause. Ex:However, you can’t be sure that the next thread running will be the UI thread, where
onProgressUpdate()will be run.Regards.