question

sgadmin avatar image
sgadmin asked

How to make WhysperSync refresh (load data from server)?

Hi, I have two devices (Amzon emulators) with the same account signed in and want to send data (game saves) to cloud from one device and later load it from another. On one device I do: (on "SaveToCloud" button) String str_to_send = "Random: " + Math.random(); WhispersyncClient wsync = AmazonGamesClient.getWhispersyncClient(); GameDataMap gameDataMap = wsync.getGameData(); SyncableString str = gameDataMap.getLatestString("str_name"); str.set(str_to_send); Log(str.getValue()); wsync.synchronize(); wsync.flush(); On another I do: (on "LoadFromCloud" button) WhispersyncClient wsync = AmazonGamesClient.getWhispersyncClient(); wsync.synchronize(); GameDataMap gameDataMap = wsync.getGameData(); SyncableString str = gameDataMap.getLatestString("str_name"); if (str.isSet() && str.getValue() != null && str.getValue().length() > 0) Log(str.getValue()); So I assume, when I press "SaveToCloud" button on one device and later "LoadFromCloud" on another I get the same log string. But as synchronize() fires something in background, I can see a new string only if I retry after Whispersync gets onThrottled. Or - I can sign out and fully initialize AmazonClient again (or just re-run app), and then I get the latest data from cloud. But sign-in and out every time I want data from server is awrong approach. My question is - how to force Whispersync to load data from server? Is there any way to ask data with callback? I plan to do this rarely, but I need to be sure that if user askes for data he gets the latest available data from server. Thank you for your answers!
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Sgaadmin, Thanks you for the post. Yes, we do have a asynchronous mechanism to load the latest data from cloud. I have added below lines in your code and I am able to receive the latest data from cloud when onNewCloudData() is called back by SDK. AmazonGamesClient.getWhispersyncClient().setWhispersyncEventListener(new WhispersyncEventListener() { public void onNewCloudData() { // refresh visible game data System.out.println("MyActivity.onNewCloudData"); GameDataMap gameDataMap = AmazonGamesClient.getWhispersyncClient().getGameData(); SyncableString str = gameDataMap.getLatestString("str_name"); if (str.isSet() && str.getValue() != null && str.getValue().length() > 0) System.out.println("onNewCloudData : str = " + str.getValue()); } // The following three methods are mainly useful for debugging purposes and don't have to be overridden public void onDataUploadedToCloud() { } public void onThrottled() { } public void onDiskWriteComplete() { } }); WhispersyncClient wsync = AmazonGamesClient.getWhispersyncClient(); wsync.synchronize(); //don't read latest string here, wait for the async callback (onNewCloudData()) One more point I think you should be informed with. Our Kindle emulators have some limitations and we would not recommend to test GameCircle functionality in the emulator since it is a know issue some times the emulators gives troubles to detect the currently registered user. https://developer.amazon.com/public/resources/development-tools/ide-tools/tech-docs/04-known-issues-with-the-emulator It says: GameCircle Does Not Show Account Data Even When Emulator Is Registered to an Amazon Account After you register the emulator to an Amazon account, GameCircle 2.0 may show a guest account, or not show an account at all. GameCircle features such as Leaderboard and Achievements do not display the GameCircle data for the Amazon account. To remedy these issues, close the emulator window and restart the AVD, and make sure that you clear the Wipe user data check box.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.