I've a mapview which needs to display plenty of overlay from the network. Now my current design is using AsyncTask
where in a socket connection is open in doInBackground()
and in publishProgress()
it displays the overlay on the mapview.
Now the problem with this design is:
ItemizedOverlays<Overlayitem>
) about 100 or so which allocates some memory during the data processed. Next with overlay the map tiles has also to load, where in I run in memory problems of Grow Heap (frag case)
as it has to load bitmaps (although I'm using AsyncTask
to load and display in parallel executor).ANR
dialog pops up.AsyncTask
has to be running in the background for most of the time.Now my plan is to move this AsyncTask class to IntentService class where this socket connection can be open most of the time, but how would I make it communicate with the FragmentActivity
? Before moving to that, would it make sense to move to IntentService
or Service
at all from AsyncTask
class that I'm already using?
Note: The only reason the I want to move to IntentService
or Service
is that I'm running into memory issues, and most of them by allocated memory to bitmap (maptiles). I tried cleaning the maptile cache as well, by not much luck. I tried calling System.gc()
in a Timer
thread to some extent it seems working, but long term not sure how it would perform.
EDIT:
Bottom line is GC
is causing my app to slow down. Also please have a look at this link, how I'm actually loading my maptiles: optimize android code snippet - better design approach?
As a heads up, the maptiles loading is quite fast and good when no overlays are there. Its only when data is received through network, and tried to overlay on it, GC
triggers multiple times.
Based on the comments it sounds like the GC is causing the app to slow down. How about instead of recycling your Bitmaps, you reuse them.