I am listening to a broadcast through a BroadcastReceiver
. The nature of my requirement isneeding me to load some sizable data from SQLite DB in a very time sensitive manner. I need the data fast. The ideal way for me to have the data pre-loaded and prepared before BroadcastReceiver.onReceive
hits.
What's an ideal way to do this?
This is the approach I have taken:
Problem was delay in data. I created another table with most minimal set of columns from each source tables that are important for processing when BroadcastReceiver
starts (or in turn starts a Service
).
This new table is designed to keep the cartesian product of the join between all the tables I need, down to the granularity of the column which I am using to search (where
clause). This table is recreated through a Service
that manages a Thread
. This thread processes all data and "digests" it so that its in the most easy form of processing by the app. It saves the digested data to the table. I didn't use IntentService
because there's no way to stop a running worker thread.
All I'm doing now is to query the DB when Service
starts and get the absolute row that I want from the SQLite DB and work on it. Since it is already simplified in terms of how app can easily start processing it, there's no other overhead on processing time. We just get down to the business as soon as I have the result.
This isn't still the most perfect way I imagined my final approach to be, but given the current speed of SQLite database access, it works fine.