0

Hey i'm using AsynHttpClient.

I would like to implement my get and set functions in one Activity where they can get called by others.

But how can i call my custom callback from the reponse callback?

I dont get it how it works in an inner class

 public void requestApiUrl(Callback callback ){
    JSONObject jsonObj = new JSONObject();
    try {
        jsonObj.put("AppKey",getResources().getString(R.string.AppKey));
        AsyncHttpClient client = new AsyncHttpClient();
        StringEntity entity = null;
        try {
            entity = new  StringEntity(jsonObj.toString());
            entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
            client.get(this, "***************URL***********", entity, "application/json", new JsonHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, cz.msebera.android.httpclient.Header[] headers, JSONObject utils) {
                    super.onSuccess(statusCode, headers, utils);
                    Log.d("HTTP", "response: " + utils.toString());
                    callback.reponse();
                }

                public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, String responseString, Throwable throwable) {
                    super.onFailure(statusCode, headers, responseString, throwable);
                    Log.d("Failed: ", "" + statusCode);
                    Log.d("Error : ", "" + throwable);
                    callback.reponse();
                }
            });

    }catch (JSONException e) {
        e.printStackTrace();
    }
}
Fesco
  • 147
  • 1
  • 14

1 Answers1

0

As far as i could get out of your question, you need to call a function from child/inner class where the function belongs to the parent/outer class. Quoting the answer from this question

For a class

class Outer {
    void show() {
        System.out.println("outter show");
   }

   class Inner{
       void show() {
            System.out.println("inner show");
                   }
              }
}

you can simply call

Outer.this.show();
Community
  • 1
  • 1
Aqib Bangash
  • 963
  • 1
  • 8
  • 22