tony9099
tony9099

Reputation: 4717

Database tasks inside asynctask or no

Should I perform every single DB related operation inside an asynctask ? (or similar background processing thread).. even for example small operations like updating a single column value ? or adding a 3 columned row into the db ?

Upvotes: 0

Views: 58

Answers (1)

s.d
s.d

Reputation: 29436

That really depends on how much time that operation takes. Long running operations will make UI thread wait, and app will appear to be frozen.

The code you now have may appear to be very quick but regard future circumstances carefully. Database may grow too large or there may be an IO lag etc.

Also consider frequency of such operation, a separate database query when each item of a ListView is being scrolled into view is not really efficient.

But if its an un-frequent work and its clear that it would always take a very very small time to run, there is nothing wrong with doing it on UI thread.

Upvotes: 1

Related Questions