Question

I am implementing a library function that performs a query on the database and this query can sometime be long enough to cause a StrictMode warning for a long operation on the UI thread.

I was wondering what would it be the right pattern to apply here? How can I wrap an asynchronous call in a function which result is expected to be synchronous?

The function gets a table name and column and returns a boolean using the normal Cursor / resolver.query pattern functionalities. I can add the code if needed.

Thanks a lot, Andrea

Was it helpful?

Solution

You can do anything from a simple Runnable executed by a new Thread to an AsyncTask. An AsyncTask is the "Android way"; otherwise you need to create a Handler so the Runnable (or Thread.run()) can report the results back on the UI thread. The docs for AsyncTask have a lot of details on usage and the API guide topic Processes and Threads has more information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top