1

I am sending request to server and getting response,and sending response to next activity,in response I have so many fields it looks like this
http://gujjumatch.com/webservice/searchresult?version=apps&user_login_id=2650
,but when I am sending to next activity,only one jsonobject is sending instead of whole objects can anyone help me with this?

 public class SearchResults extends ListActivity{

private ProgressDialog pDialog;
private String Id;
private String results;

 private ArrayList<HashMap<String,String>> aList;
    private static String MATCH_URL = null;
    private static final String TAG_MATCH="searchresult";
    private static final String TAG_MATCH_ID="match_detail_id";
    private static final String TAG_NAME="name";
    private static final String TAG_PROFILE="profile_id";
    private static final String TAG_IMAGE="image";
    private static final String TAG_CAST="cast";
    private static final String TAG_AGE="age";
    private static final String TAG_LOCATION="location";
JSONArray searchresult=null;
private CustomAdapterSearch adapter;
private TextView nomathc;
private String Nam;
private String Pro;
private String Photo;
private String Jati;
private String Umar;
private String Jagya;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_view_searchresult);
    Id=this.getIntent().getStringExtra("id");
    System.out.println("searching id"+Id);
    results=this.getIntent().getStringExtra("prmatch_id");
    System.out.println("Results"+results);
    Nam=this.getIntent().getStringExtra("prname");
    System.out.println("Naam"+Nam);

    Pro=this.getIntent().getStringExtra("prprofile");
    System.out.println("Profilesss"+Pro);
    Photo=this.getIntent().getStringExtra("primage");
    System.out.println("Naam"+Photo);
    Jati=this.getIntent().getStringExtra("prcast");
    System.out.println("Naam"+Jati);
    Umar=this.getIntent().getStringExtra("prage");
    System.out.println("Naam"+Umar);
    Jagya=this.getIntent().getStringExtra("prlocation");
    System.out.println("Naam"+Jagya);

    aList = new ArrayList<HashMap<String,String>>();
    HashMap<String,String> idMap = new HashMap<String,String>();
    idMap.put(TAG_MATCH_ID, Id);
    idMap.put(TAG_NAME, Nam);
    idMap.put(TAG_PROFILE, Pro);
    idMap.put(TAG_IMAGE, Photo);
    idMap.put(TAG_CAST, Jati);
    idMap.put(TAG_AGE, Umar+" years");
    idMap.put(TAG_LOCATION, Jagya);
    aList.add(idMap);
    //.... 

    adapter = new CustomAdapterSearch(SearchResults.this, aList); // we create your adapter

   setListAdapter(adapter); // we set the list adapter

    nomathc=(TextView)findViewById(R.id.no_match);


}
  • try to use SharedPreference.. Check: http://stackoverflow.com/questions/23024831/android-shared-preferences-example – Amitabha Biswas Dec 13 '14 at 07:08
  • you can see my code here http://stackoverflow.com/questions/27444526/arraylisthashmapstring-string-not-set-to-listview/27456030#27456030 –  Dec 13 '14 at 07:10

2 Answers2

0

There are 2 solutions for this

Solution A:

  1. JSON object -> JSON String
  2. putStringExtra in the intent
  3. Start the activity
  4. getString extra in onCreate / onNewIntent

Solution B:

When the size of the json string is huge, i.e, more than 1MB, it could cause ANR while parcelling. So, following approch

  1. JSON Object -> JSON string
  2. Write to a temp file
  3. Pass the file location in putStringExtra
  4. Start the activity
  5. getStringExtra if not null, read from the received file.
-2

You only need to have one string with all the object..

 JSONObject json =  YOU JSON Object.

   String myObject = json.toString();

Intent i = new Intent(this, SecontActivity.class);
i.putExtra("KEY",myObject);

In the secont activity.

Bundle extras = getIntent().getExtras();
if(extras !=null) {
    String value = extras.getString("KEY");
} else {

String value = "Error";

}


JSONObject json = (JSONObject) new JSONParser().parse(value);
Gilberto Ibarra
  • 2,849
  • 2
  • 27
  • 38
  • you can see my code here http://stackoverflow.com/questions/27444526/arraylisthashmapstring-string-not-set-to-listview/27456030#27456030 –  Dec 13 '14 at 07:09
  • Yep... In your AsynkTask you should sent the JSOnObject like a String to the other activity. Intent intent=new Intent(getActivity(),SearchResults.class); intent.putExtra("myJSONString", json.toString()). And is better use Objects instead ArrayList – Gilberto Ibarra Dec 13 '14 at 07:18
  • instead of handling the JSON object in your AsyncTask, simply send it as a string to the next activity, and drive it in the activity that you need. – Gilberto Ibarra Dec 13 '14 at 07:31
  • thats what i am doing but only single object is receiving at next activity,not all –  Dec 13 '14 at 07:32
  • in your code in the other activity, you dont are doing that. – Gilberto Ibarra Dec 13 '14 at 07:42