Pergunta

I'm working on an android app which syncs across devices using datastore api provided by dropbox. It has a set of metadata that needs to be uploaded to dropbox the first time user connects his account with the app. For next device logging in with same dropbox account, the metadata need not be created again (since it's already present).

To achieve this, I make a query to check with the metadata is already present, before inserting the record.

The issue is, I get empty result on my query even when the record is present in the table. I'm calling sync() method before doing this check, but seems like the api checks with the local datastore and confirms back with empty result.

I'm not sure if this is expected, but one of the work around could be: - Provide a sync completed callback/event, for the application to be certain that download/upload has completed. (or) - For a query, there should be a way to check with the server as well, to see if there are any existing records (though it's not favorable coz of increase in query time).

Any suggestions would be welcome. Thanks

Foi útil?

Solução

"Sync completed" is a problematic term... the Datastore API is continually syncing. You can use DbxDatastoreStatus to see if there are any known changes currently in flight. When you first link an account, the isDownloading field should be true, so you could use that to gate on the "first sync."

As for your use case of adding initial data, you might want to instead use getOrInsert with a known ID (like "metadata"). That way even if the record is created on multiple devices, you'll still end up with only one record.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top