Skip to content
darrenkopp edited this page Jul 31, 2012 · 1 revision

The simplest usage of the driver.

Driver driver = new DriverImpl(gameKey, secret);
Response> response = driver.getAchievements();
if (response.wasSuccessful()) {
    List achievements = response.getData();
    // do something with the achievements
} else {
    ErrorMessage message = response.getError();
    // do something with the error
}

All of the methods on the driver are synchronous, so you will want to wrap it's usage into an AsyncTask for most scenarios.

private class DownloadAchievementsTask extends AsyncTask>> {
     protected Response> doInBackground(Void... voids) {
        Driver driver = new DriverImpl(gameKey, secret);
        Response> response = driver.getAchievements();
        return response;
     }

     protected void onProgressUpdate(Integer... progress) {
         // not actually using progress
     }

     protected void onPostExecute(Response> result) {
        if (result.wasSuccessful()) {
            showDialog("Downloaded " + result.getData().getLength() + " achievements.");
        } else {
            showDialog("Failed to download achievements.");
        }
     }
 }
Clone this wiki locally