0

I want to use json result to another activity.Here following code I want to use intents to pass the data second activity but I am not able to intents class.How can i use intent to pass the value

 if (status == 200) {
    HttpEntity entity = response.getEntity();
    String data = EntityUtils.toString(entity);
    System.out.println(data);



    System.out.println("fffff");
    JSONObject jsono = new JSONObject(data);
    JSONArray jarray = jsono.getJSONArray("articles");
    System.out.println(jarray);
    for (int i = 0; i < jarray.length(); i++) {
        JSONObject object = jarray.getJSONObject(i);

        Dashboard_Model_File actor = new Dashboard_Model_File();
        actor.setTitle(object.getString("category_name"));
        actor.setDescription(object.getString("bookmark_title"));
        actor.setUrl(object.getString("bookmark_website"));

        actor.setBookmark_id(object.getString("bookmark_id"));
        actor.setAlternate_id(object.getString("alternate_id"));
        actor.setBookmark_file(object.getString("bookmark_file"));
        actor.setMode(object.getString("mode"));

        actor.setImage(object.getString("bookmark_preview_image"));

        actorsList.add(actor);
    }
    return true;
}
INDIA IT TECH
  • 1,902
  • 4
  • 12
  • 25
pawan kumar
  • 61
  • 10

4 Answers4

1

i recommended to send JSON result as string see the following code

Intent intent=new Intent(getApplicationContext(),DistClass.class);
intent.putExtra("json",object.toString());
startActivity(intent);

in the second class do the following

String jsonResult=getIntent().getExtras().getString("json");
JSONObject json=new JSONObject(jsonResult);

that's all

Basil Battikhi
  • 2,638
  • 1
  • 18
  • 34
0

You should read this here:

https://github.com/google/gson

same gson you can send to the other activity or store as the sharedPreference and access the shared prefs in another activity.

or there is a silly way to convert to string and send in intent with putExtras and access it in another activity as getExtras and parse again in the other activity.

Happy Coding

Akshay Kulkarni
  • 729
  • 6
  • 22
0

Try this -

Parse data in string

String categoryNameData = object.getString("category_name");  //Do this for all data object

Check if data is not null and then pass intent

if(categoryNameData != null){
Intent intent = new Intent("YourCurrentActivityName".this , "TargetActivityName".class);
intent.putExtra("cat" , categoryNameData);    //do this for all data objects
startActivity(intent);
}

In Target Activity

String category = getIntent.getStringExtra("cat");

Hope this will help :)

Onkar Nene
  • 1,359
  • 1
  • 17
  • 23
0

Rather than using shared pereferences or some other tactics:

Simple and easy solution use Singleton patteren parse you json result and set and get the values, like this :

public class RecentRequest {

String recieverName;
String dateTime;
String receiverNumber;

public String getRecieverName() {
    return recieverName;
}

public void setRecieverName(String recieverName) {
    this.recieverName = recieverName;
}

public String getDateTime() {
    return dateTime;
}

public void setDateTime(String dateTime) {
    this.dateTime = dateTime;
}

public String getReceiverNumber() {
    return receiverNumber;
}

public void setReceiverNumber(String receiverNumber) {
    this.receiverNumber = receiverNumber;
}
}     

Please let me know if u need any other help!! Cheers !!

Jhaman Das
  • 1,094
  • 13
  • 28