kar mac
kar mac

Reputation: 128

Content provider return cursor in asynchronous way

I have 2 android apps, the first one (written in Kotlin) provides data to the second app using content provider. How can I return cursor in query function asynchronously?

**In ContentProvider class**

 override fun query(p0: Uri, p1: Array<String>?, p2: String?, p3: Array<String>?, p4: String?): Cursor? {
        val cursor = MatrixCursor(arrayOf("id", "name"))

        // async fun
        ContactsHelper(context).getContacts {
            for (contact in it) {
                cursor.newRow()
                        .add("id", contact.contactId)
                        .add("name", contact.firstName)
            }
        }

        return cursor
    }


**in ContactsHelper class**

fun getContacts(ignoredContactSources: HashSet<String> = HashSet(), callback: (ArrayList<Contact>) -> Unit) {
        Thread {    
                callback(...)            
        }.start()
    }

Returned cursor does not contains data, How can I add data to cursor then return it?

Upvotes: 0

Views: 829

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007474

How can I return cursor in query function asynchronously?

You can't. query() needs to be synchronous.

Upvotes: 0

Related Questions