json - Use AsyncTask or Thread for frequent read/write operations - Android -


i have built android app allows user create new levels game making. level maker app allows user save new levels , preview levels have saved. when user saves level, app generates jsonobject represents level, writes jsonobject.sostring() value local file (either shared preferences file or plain old .txt file - don't know better yet). when user wants preview existing levels, app reads in json strings levels file, converts each json bitmap (json -> viewgroup -> bitmap), displays bitmaps in listview.

right using 2 asynctasks: 1 writing , 1 reading. don't know if potentially spawning 5-10 new threads per minute, though (one each time user saves new level), , don't know if bad thing far system resources goes.

here's question: because may need write levels file 5-10 times per minute, better start new asynctask each time user saves new level, or should create 1 background thread , execute runnables on each time user saves or previews levels?

asynctask controlled internally shared (static) threadpoolexecutor , linkedblockingqueue. there such parameters core pool size , maximum pool size. since android 1.6, core pool size 5, , maximum pool size 128. queue size 10 tasks.

so, maximum quantity of parallel asynctasks 5, others queued. if save operation relatively slow, may encounter situation when asynctask got killed os , nothing saved. if need long-running save operation, better use service.

for me, prefer using background service own threadpoolexecutor - gives me control cancelling tasks. if don't want write code, may use intentservice - uses executor , queues tasks itself.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -