Swarm Documentation API Reference

Swarm's Callback Architecture

Swarm is an asynchronous platform. Since most actions involve pushing or pulling data from our servers, many of the methods you may call will return their results in a callback. Throughout Swarm, callback classes end in CB, and are generally named to match the action you requested (examples: GotLeaderboardCB, SubmitScoreCB, ItemPurchaseCB, etc). Swarm method calls are automatically threaded to the background for you, so you don't need to worry about tying up the application's Main thread (which can cause "Application Not Responding" errors).

Calls to Swarm methods that (might) take time, are automatically threaded for you. If you call a Swarm method from a thread that is a Handler (has called Looper.prepare()), such as the Main UI thread, any callback will be executed back on the original thread. If you call a method from a non-Handler thread, callbacks will be executed on the background thread, as there is no way to post them back to the original thread. What does this mean for you?

It is perfectly safe to call Swarm methods from the UI Thread.

Callback Delays
Swarm was built from the ground up with speed in mind, however, some network connections are inherently slower than others. Callbacks are called whenever the data you requested is available. On average, callbacks can take a few hundred milliseconds to be executued, however in many cases, they will be called back immediately if the data is already cached and available.

Plan for a ~200ms delay between call, and callback.