-2

This is my class whose list I want to send to another activity.

public class PostComments {

    public User from;

    public String message;

    public String createdTime;

    public String like_count;

    public Boolean user_likes;
}

This is User class whose object is used in PostComments class.

public class User extends BaseEntity{
    public String photoUrl;
}

And this is BaseEntity Class

public class BaseEntity {
    public String Id;

    public String Name;
}

How can I send this object from one activity to another?

PostComments[] myData = ClickedPost.comments.data;
Intent PostCommentsActivity = new Intent(getActivity() , PostCommentsActivity.class);
getActivity().startActivity(PostCommentsActivity);

Above is the code to open PostCommentsActivity and I want to send myData object to the PostCommentsActivity.

I have searched alot about this problem but every question and tutorial explain that only for a class which contains simple string, int or boolean variables.

Yawar
  • 1,846
  • 3
  • 24
  • 38
  • Why do you want to send that much data over? Why not just send an ID of an object and then retrieve/construct that object at the destination? – Aleks G Oct 10 '14 at 08:13
  • All else failed, you can always serialise the object and deserialise at the destination. – Aleks G Oct 10 '14 at 08:13
  • I just want to show this array of my comments on second activity by any means. Can you provide some link that how can I do that? – Yawar Oct 10 '14 at 08:15

1 Answers1

1

Let's try:

ArrayList<PostComments> comments = new ArrayList<MainActivity.PostComments>();
comments.add(...) //Add your list data here
Intent intent = new Intent(getActivity() , PostCommentsActivity.class);
intent.putExtra("list_comments", comments);
getActivity().startActivity(intent);

And edit your PostComments Class to:

public class PostComments implements Serializable {

        public String message;

        public String createdTime;

        public String like_count;

        public Boolean user_likes;
    }

In PostCommentsActivity, get bundle to get list comments.

Truong Phu Quoc
  • 529
  • 4
  • 9