I am trying to send data to server and in response i am getting some data which i need to display in next activity using listview,can any one tell me how to do this?
-
use shared prefrences or a singleton class – Murtaza Khursheed Hussain Dec 05 '14 at 10:08
-
what type of data you have to pass like : String,Object,List etc ? – Haresh Chhelana Dec 05 '14 at 10:13
-
i am sending data to server in text and getting response in text – Dec 05 '14 at 10:20
-
In which format you are getting data? If `json`, you can send direct as `json.toString()` – Pratik Butani Dec 05 '14 at 10:23
-
1You said you are sending text to server and getting text in response, that you want to send to next activity. So what about images now? – Darpan Dec 15 '14 at 07:05
-
this question is asked many times in many different ways, please consider doing a search. – Ercan Dec 16 '14 at 10:03
6 Answers
use bundle
to move your response from one activity to another
-create class that implements Parcelable
public class ResponseData implements Parcelable{}
-Next save it in intent:
intent.putExtra(key, new ResponseData(someDataFromServer));
-Last step - retrive it:
Bundle data = getIntent().getExtras();
ResponseData response= (ResponseData ) data.getParcelable(key);
After that add it to an adapter to display it for the user
In other case you can save it in application context or database (not recommended)

- 1,587
- 15
- 33
I would strongly suggest you to pass necessary parameters to next activity using Bundle
and from next activity itself you should make a call to server to receive and display necessary information.

- 15,348
- 6
- 48
- 57
Send data to server using AsyncTask
After getting result in doInBackground , continue with onPostexecute()
- Start the next activity in onPostexecute()

- 7,397
- 5
- 44
- 59
-
ok i am sending data using some fields like country,mother tongue,religion.it is kind of searching users list..and in response i will get user's name in list which i need to show in next activity. – Dec 05 '14 at 10:13
-
http://stackoverflow.com/questions/7578236/how-to-send-hashmap-value-to-another-activity-using-an-intent?answertab=oldest#tab-top Is it ok for you ? – Don Chakkappan Dec 05 '14 at 10:15
Try using an event bus library, such as greenrobot EventBus. With it, the process will be done in 4 lines of code:
(In sender Activity)
EventBus.getDefault().register(this);
EventBus.getDeafult().postSticky(myDataObject);
(In receiving 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, quick and elegant :-)

- 7,024
- 2
- 29
- 46
- Send data to server
Get the response
Put that string as Extra in Intent and start activity
Intent i = new Intent(this, YourNextActivityName.class);
i.putExtra("res",response.toString);
i.startActivity();On Next Activity get that Data and display.
Bundle extras = getIntent().getExtras(); if (extras != null) { String response= extras.getString("res"); }

- 594
- 5
- 19
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.

- 10,224
- 2
- 37
- 59