Thursday 15 April 2010

java - android-async-http return json values from onSuccess method -


I am working on this app, I use android-async-http lib, the problem comes when I Trying to go back to the value from the JSN that the API sends me.

So, I have a name that requests all the APIs called SyncNotesHandler and needs to return an object back inside JSN. Here's the square:

  Public class SyncNotesHandler {public SyncNotesHandler (reference reference) {this.context = context; } Public Zero getNotesFromuser (string token) {Log.i ("Debugin", "Here comes around"); Header [] header = {new basic header ("authorization", token)}; Client.get (this.context, "http://104.131.189.224/api/notes", header, blank, new JsonHttpResponseHandler () {success on public zero (int status code, header [header], JSONObject json) {log .i ("debugin", "get feedback"), try {log (i. ("Debugin", "response:" + json.toString ()); note.cetital (json.toString ());} catches (Exception e) {Log.i ("debugin", "error")}}} Public zero (int status code, header [header], string response string, throwable throbable) on Failer {Log.i ("Debugin" , "Failure")}}} ); Logs. I ("debugin", "pre-final:" + note. GetTitle ()); } PublicNote getNoteResponse () {Log.i ("Debugin", "Final:" + note.getTitle ()); Turn it back. note; } Public Zero Starter () {this.note = new note (); This.notes = new ArrayList & lt; Note & gt; (); This.client = new AsyncHttpClient (); This.status = 0; } Public zero end () {this.note = null; This.notes = null; This.client = null; This.status = 0; } Private Static AsyncHttpClient Client; Private note notes; Private Arrestist & lt; Note & gt; notes; Personal reference references; Private fulfillment status; }  

Here I call all the tasks:

  signatures handler s = new SyncNotesHandler (getApplicationContext ()); S.start (); S.getNotesFromuser ("e6bc9f7c1e74cb3dd8ccde07e6edbc32"); Note Note = s.getNoteResponse (); S.end ();  

If you see the code, and the flow which I think should follow the code: method getNotesFromUser () -> enter onsite < / Code> method -> method getNoteResponse () should be entered and log history:

  debugin: Comes here Debugin: Receiving response Debugin: Response : {Jason} Debugin: Pre-Final: {Jason} Debugin: Final: {Jason}  

But the real log history shows supernatural things, its strange , And I do not know how to solve it:

  03-17 12:17, 56.441 7369-7369 / com.example.usuario.androidadmin I / Debuggin: here comes 03-17 12:17: 56.451 736 9-736 9 / com.example.usuario.androidadmin I / Debuggin: Pre-Final: Faucet 03-17 12: 17: 56.451 7369-7369 / Com. Explorer.eurioro Android advertising I / Debuggin: Last: Faucet 03-17 12:17: 56.878 7369-7369 / com.example.usuario.androidadmin I / debuggin: getting response 03-17 Dec: 17: 56.885 7369-7369 / com.example "Q Pepsi", "Favorite": "Title": " The problem is that onSucces comes from any other process, and the tasks are called from syncNotesHandler is the first need to conclude: true, "status": false}]}  

And after onSuccess So the problem is that I need to give value to Json, but I do not know how to do it.


No comments:

Post a Comment