After sending data to the server, how to print the response in the next step?

I'm trying to send data to a server, and in return I get some data that I need to display in the next step using listview, can someone tell me how to do this?

+8
json android android-listview
source share
6 answers

use bundle to move the response from one action to another.

-create class that implements Parcelable

  public class ResponseData implements Parcelable{} 

-Next keep it int:

 intent.putExtra(key, new ResponseData(someDataFromServer)); 

-Last step - extract it:

 Bundle data = getIntent().getExtras(); ResponseData response= (ResponseData ) data.getParcelable(key); 

After that, add it to the adapter to display it to the user.

Otherwise, you can save it in the application context or in the database (not recommended)

+3
source share

I highly recommend that you pass the necessary parameters for the next action , using the Bundle and from the next action itself, you should make a call to the server to receive and display the necessary information.

+1
source share
  • Sending data to a server using AsyncTask

  • After getting the result in doInBackground, continue onPostexecute ()

  • Run the following operation in onPostexecute ()
0
source share

Try using an event bus library such as greenrobot EventBus. The process will be performed in 4 lines of code:

(In the work of the sender)

 EventBus.getDefault().register(this); EventBus.getDeafult().postSticky(myDataObject); 

(Upon receipt of activity)

 DataObject passedData = EventBus.getDefault().getStickyEvent(DataObject.class); 

You will also need a POJO data class:

 public static class DataObject{ private String data; public String getData(){ return data; } public void setData(String data){ this.data = data; } } 

Clean, fast and elegant :-)

0
source share
  • Sending data to the server
  • Get an answer

  • Put this line as Extra in Intent and start your activity

    Intent i = new Intent (this, YourNextActivityName.class);
    i.putExtra ("Res", response.toString);
    i.startActivity ();

  • In the next operation, get the data and display.

      Bundle extras = getIntent().getExtras(); if (extras != null) { String response= extras.getString("res"); } 
0
source share

Steps:

  1)Send data. 2)Get Response 3)if respose is ok, save that in a static string and fire intent and on the next activity get the respose using classname.your string. simple and best way. 
0
source share

All Articles