问题
I've written a small test application which works as a simple chat room using Nearby.MESSAGES_API.
When I subscribe I find that I receive a number of older Messages in my MessageListener (in onFound). If I disconnect and then reconnect (eg. switch to another application) I find that all the messages come through again. Is this meant to happen?
I have changed the application to include UUIDs in my messages and keep a stash of them to check whether I have received the message, but that may not be a good idea from a memory point of view (although I could put them in a database).
I don't understand how the "session" side of Nearby Messages works.
回答1:
In Google Play Services 7.8 the "sessions" are internally divided into ten minute buckets. You're not the first person to be confused by this, we're looking at options to do this differently in the future. No promises, but we recognize it's an issue.
(I work on the Nearby API)
回答2:
The issue was that publishAndSubscribe is called when onConnected is called. The issue with this is that onStart attempts to reconnect so publishAndSubscribe needn't be called again.
来源:https://stackoverflow.com/questions/32300786/nearby-messages-repeated-on-reconnecting