Android Question Response.GetAsynchronously() pauses the UI temporarily

Inman

Well-Known Member
Licensed User
Longtime User
In my app, I have a rich UI with Actionbar, a ViewPager that has 2 pages - each page having 30 ImageViews and Labels and so on. When the app starts, I populate this UI using the data that is already cached from the previous instance. Then while the user is going through the data, I use HttpClient to download new data that will be cached for the next instance.

Here is the problem. In the httpclient1_ResponseSuccess event, I am using Response.GetAsynchronously() to download the file. The file is actually a small zip file of size under 100KB. Now when the execution reaches the Response.GetAsynchronously() line of code, the UI lags. I mean if the user is scrolling the UI at that point, he will notice that the app gets paused for 1 or 2 seconds, before being able to continue scrolling.

I tested it on multiple devices (even Galaxy S4) and this pause is there. I know 1 second is not a big deal, but still I feel it affects the user experience to see the execution paused just like that.

Any solution for this?
 

Inman

Well-Known Member
Licensed User
Longtime User
I solved it.

The problem was not exactly with Response.GetAsynchronously event but with the StreamFinish event that gets raised after it. In the StreamFinish event I was executing a bunch of SQL Insert queries within a For loop. Even though there were only like 50 iterations or something, this slowed down the execution.

So I switched the SQL2.ExecNonQuery2 to SQL2.AddNonQueryToBatch within the loop and used SQL2.ExecNonQueryBatch just outside the loop and that was it. The execution was smooth once again.
 
Upvote 0
Top