I have a Service
which runs in the background when my app starts, and continues to run after the app is closed. It implements
a Loader.OnLoadCompleteListener<Cursor>
for a registered Uri
from a Content Provider
. When a new Cursor
object is delivered on the callback method onLoadComplete(Loader<Cursor> loader, Cursor data)
I then run an AsyncTask
using the Cursor
to create an ArrayList
of custom Objects
that implement the Parcelable
interface
. Once processed, if the app is open it sends back to the App getting marshalled/demarshalled using the IPC framework using a Handler
with Messenger
,Messages
and aBundle
. If the App is not open then the ArrayList
is ready to be sent back to the App once opened, which calls to the Service
when opened.
Problem:
The ArrayList
can get relatively large (it doesn't contain Bitmaps
, only Primitives
and several short String
objects) and the sheer amount means it hits the FAILED BINDER TRANSACTION
when the ArrayList
gets to about 700 objects.
Current Solution (that feels a bit hacky)
I am splitting the ArrayList
into chunks and sending several Messages
back to the Handler
where it is then reconstructed into one ArrayList
and then used in the App (updating RecyclerViews etc..).
I use this approach as the performance is significantly improved - only need to do initial query when App/Service is started first time, rather than always querying the Content Provider
every time the App is opened.
The reason I say 'hacky' is because this feels like a workaround for a limitation of the Binder Framework
rather than a solution.
Any advise on approaching this differently would be welcomed.