0

i have json to serializable claas then i use it to populate listview, and everything works fine but i want to populate textview on another xml page with one of the serializable object and i read to best way to do it is bundle intent, but i did code something wrong.

public class FeedItem implements Serializable {

    private String title;
    private String date;
    private String attachmentUrl;
    private String id;
    private String content;
    private String url;

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getAttachmentUrl() {
        return attachmentUrl;
    }

    public void setAttachmentUrl(String attachmentUrl) {
        this.attachmentUrl = attachmentUrl;
    }




    @Override
    public String toString() {
        return "[ title=" + title + ", date=" + date + "]";
    }

    ArrayList<FeedItem> all_thumbs = new ArrayList<FeedItem>();
    all_thumbs.add(new FeedItem(title);
    Intent intent = new Intent(title);

    Bundle extras = new Bundle();

    extras.putSerializable("title",title);
    intent.putExtras(extras);

}

and in the class where i want to use it

public void updateList() {

    TextView infoz = (TextView) getView().findViewById(R.id.infoz);
    Bundle args;
    getArguments().getSerializable(title);
async
  • 1,537
  • 11
  • 28
  • What's wrong ? Do you get any exception? – Blackbelt Nov 08 '13 at 12:33
  • Use Parcelable instead of Serializable: http://stackoverflow.com/questions/5550670/benefit-of-using-parcelable-instead-of-serializing-object – JJ86 Nov 08 '13 at 12:34
  • on class where i want to use it: title cannot be resolved to a variable. in the serializable class Multiple markers at this line - Syntax error on token ""title"", invalid FormalParameterList - Syntax error on token(s), misplaced construct(s) - Syntax error on token "title", VariableDeclaratorId expected after this token Multiple markers at this line - Syntax error on token "add", = expected after this token - Syntax error on token(s), misplaced construct(s) – Sandra Mladenovic Nov 08 '13 at 12:34

2 Answers2

0

Instead use:

public void updateList() {

    TextView infoz = (TextView) getView().findViewById(R.id.infoz);
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    String title = (String) extras.getSerializable("title");
frogmanx
  • 2,620
  • 1
  • 18
  • 20
0

IF you want to pass any primitive datatyped values (String,int,long,float etc.) then do not need to use Bundle.putExtra(KEY,Serialized Object) and Bundle.getSerializable(KEY). You can use Bundle.putExtra(KEY,primitive data);

If you want to pass class object to intent/bundle then you need to implement Serializable/Parsable in that class like:

public class Test implements Serializable
{
   private static final long serialVersionUID = 1L;
   int test1;
} 

and then you can pass that object instance to intent like:

myIntent.putExtra( KEY, new Test() );

For more clarification check pass seriable object in intent example

Himanshu Dudhat
  • 1,609
  • 3
  • 14
  • 27
  • **in feeditem serializable class **public void save(){ Intent i = new Intent(); i.putExtra(title, title); } ** fragment class ** Intent intent = getActivity().getIntent(); Bundle extras = intent.getExtras(); String title = (String) extras.getSerializable("title"); infoz.setText(title); But app force closes, why? – Sandra Mladenovic Nov 08 '13 at 14:33
  • you just need to write i.putExtra("title", title) instead of i.putExtra(title, title); – Himanshu Dudhat Nov 09 '13 at 10:50