Passing and Recieveing Values between Activities

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

arraylist of customized objects between activites

Postby sheshi85 » Mon Jun 22, 2009 3:11 pm

Hello everyone,
I am a beginner that i just passed data between activites.Now I wanted to pass a arraylist of customized objects between activites.Though some discussion in the site is made on how to do it,I am not clear.i read the customized class needs to implement Serializable or parcelable.Is it the solution for customized class,or is there any solution.From 2 days working hard but in vain.can Some one address this problem please!!!!.
sheshi85
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Jun 08, 2009 11:17 am

Top

Re:

Postby tessomc » Mon Oct 25, 2010 1:47 pm

Lets say that im trying to pass an ArrayList from one activity to another and im using your example
Code: Select all
ArrayList<ObjetoSimples> listasObjetoSimples = new ArrayList<ObjetoSimples>();
...populate the array...
HashMap meMap=new HashMap();
      
meMap.put("mystream",listasObjetoSimples);
      
Intent myIntent = new Intent(this, Tela2.class);
myIntent.putExtra("memap",meMap);
...



and in Tela2.class

Intent getIntent=getIntent();
ArrayList<ObjetoSimples> mystreamagain = getIntent().getExtra("memap").get("mystream");



what i'm i doing wrong? i removed the () from getIntent() but still have some errors.

Any thoughts?

Thanks!
tessomc
Freshman
Freshman
 
Posts: 2
Joined: Mon Oct 25, 2010 1:12 pm

Re: Passing and Recieveing Values between Activities

Postby salvosq » Tue Nov 02, 2010 8:40 am

Are you searching for getParcelable and putParcelable ?
:wink:
salvosq
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Nov 02, 2010 8:37 am

Re: Passing and Recieveing Values between Activities

Postby blundell » Tue Nov 02, 2010 12:00 pm

Your putExtra is fine.

When your recieving it, I have come across an error and have to do:
Code: Select all
Serializable data = getIntent().getSerializableExtra("memap");
                if(data != null){
                        HashMap<String, Object> hm = (HashMap<String, Object>) data; // Dont know WHY it won't let me cast straight to my object
                }


Just change this from HashMap to your ArrayList, can't really explain this code but hope it helps :-)
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top
Previous

Return to General

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests