Android Open Source - proximo Async Backend Helper

From Project

Back to project page proximo.


The source code is released under:

Copyright (c) 2010 Evan Martin. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: *...

If you think the Android project proximo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

// Copyright (c) 2010 Evan Martin.  All rights reserved.
// Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE file.
/*www  .  j  a  v a  2  s  .  c  om*/
package org.neugierig.proximo;

import android.content.*;
import android.util.Log;

// AsyncBackendHelper provides a UI-side counterpart to AsyncBackend.
// It has hooks into (and expects callbacks from) an Activity and
// manages displaying the "Network Error" dialog.
class AsyncBackendHelper implements AsyncBackend.APIResultCallback {
  public interface Delegate {
    // Return the result of a query.  If there was an error, it will
    // never get called.
    public void onAsyncResult(Object obj);

  AsyncBackendHelper(Activity activity, Delegate delegate) {
    mActivity = activity;
    mDelegate = delegate;
    mBackend = new AsyncBackend(activity);

  public void start(AsyncBackend.Query query) {
    mQuery = query;

  public void restart() {
    mBackend.startQuery(mQuery, this);

  public void onAPIResult(Object obj) {

  public void onException(Exception exn) {
    mBackendError = exn;

  public Dialog onCreateDialog(int id) {
    switch (id) {
      case ERROR_DIALOG_ID: {
        DialogInterface.OnClickListener clicker =
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                  case DialogInterface.BUTTON1:
                  case DialogInterface.BUTTON2:

        return new AlertDialog.Builder(mActivity)
            .setTitle("Server Error")
            .setPositiveButton("Retry", clicker)
            .setNegativeButton("Cancel", clicker)

    return null;

  private static final int ERROR_DIALOG_ID = 0;     // XXX how to choose?
  private Activity mActivity;
  private Delegate mDelegate;
  private AsyncBackend mBackend;
  private Exception mBackendError;
  private AsyncBackend.Query mQuery;

Java Source Code List