0

I have parsed the json response using the pojo classes and I want these values to be carried to another activity and there I want to show them in adapter view.

FeedPojo.java

public class FeedPojo {
private static String id;
    private static String partnerId;
    private static String type;
    private static String name;
    private static String description;
    private static String start;
    private static String text;
    private static String photoUrl;
    private static String videoUrl;
    public FeedPojo(String id,String type,String name,String description,String start){

            this.setId(id);
            this.setType(type);
            this.setName(name);
            this.setDescription(description);
            this.setStart(start);
    }
public FeedPojo(String id,String text,String photoUrl,String videoUrl,String isNew){

        this.setId(id);
        this.setText(text);
        this.setPhotoUrl(photoUrl);
        this.setVideoUrl(videoUrl);
        this.setIsNew(isNew);

    }
}

MainActiviy.java

    FeedPojo feedPojoNews = new FeedPojo(
promoJsonObject.getString("id"),                                                                                                              promoJsonObject.getString("text"),                                                                promoJsonObject.getString("photoUrl"),                                                                promoJsonObject.getString("videoUrl"),                                                                promoJsonObject.getString("isNew"));
    Log.d(TAG, "FeedPojoNewsId" + feedPojoNews.getId());                                                Log.d(TAG, "FeedPojoNewsText" + feedPojoNews.getText());                                                Log.d(TAG, "FeedPojoNewsPhotoUrl" + feedPojoNews.getPhotoUrl());                                                Log.d(TAG, "FeedPojoNewsVideoUrl" + feedPojoNews.getVideoUrl());                                                Log.d(TAG, "FeedPojoNewsisNew" + feedPojoNews.getIsNew());           FeedPojo feedPojoPartnerGn = new FeedPojo(promoJsonObject.getString("id"),                                                                                                                                    
    promoJsonObject.getString("text"),                                                                        promoJsonObject.getString("photoUrl"),                                                                    promoJsonObject.getString("videoUrl"),                                                                                                                                                                                       Log.d(TAG, "FeedPojoPartnerId" + feedPojoPartnerGn.getId());
    Log.d(TAG, "FeedPojoPartnerImageurl" + feedPojoPartnerGn.getPhotoUrl());
    Log.d(TAG, "FeedPojoPartnerbuyUrl" + feedPojoPartnerGn.getVideoUrl());
user1918566
  • 221
  • 1
  • 5
  • 18
  • You can pass the Object through Intent or Bundle if it is not serialize. First serialize you pojo class then send it to another activity. – Mukesh Y. Jun 07 '17 at 19:48
  • https://stackoverflow.com/questions/2139134/how-to-send-an-object-from-one-android-activity-to-another-using-intents?rq=1 – David Rawson Jun 07 '17 at 20:02

1 Answers1

0

implement Serializable

public class FeedPojo implements Serializable {
private static String id;
    private static String partnerId;
    private static String type;
    private static String name;
    private static String description;
    private static String start;
    private static String text;
    private static String photoUrl;
    private static String videoUrl;
    public FeedPojo(String id,String type,String name,String description,String start){

            this.setId(id);
            this.setType(type);
            this.setName(name);
            this.setDescription(description);
            this.setStart(start);
    }
public FeedPojo(String id,String text,String photoUrl,String videoUrl,String isNew){

        this.setId(id);
        this.setText(text);
        this.setPhotoUrl(photoUrl);
        this.setVideoUrl(videoUrl);
        this.setIsNew(isNew);

    }
}

then put data in bundle like this

 Bundle bundle = new Bundle();
  bundle.putSerializable("DATA", feedPojoNews);
  Intent intent = new 
  Intent(MainActivity.this,SecondActivity.class);
  intent.putExtras(bundle);
  startActivity(intent);

In second Activity Extract data like this

Intent intent = this.getIntent();
 Bundle bundle = intent.getExtras();
 FeedPojo feedPojo= (FeedPojo ) bundle.getSerializable("DATA");
Mukesh Y.
  • 869
  • 1
  • 16
  • 36