Intent.putExtra() question

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Intent.putExtra() question

Postby E-Nature » Wed Jan 06, 2010 3:09 pm

From the information I found it is not possible to send a Java object via putExtra() to a different activity. I just wanted to double check this - maybe I have overseen a solution which would make that possible.

It would be way more comfortable like this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent explicitIntent = new Intent(GameList.this, CheatTitleList.class);
  2.  
  3. explicitIntent.putExtra("gameObject", gameObject);
  4.  
  5.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


instead of this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent explicitIntent = new Intent(GameList.this, CheatTitleList.class);
  2.  
  3. explicitIntent.putExtra("gameId", selectedGameId);
  4.  
  5. explicitIntent.putExtra("gameName", selectedGameName);
  6.  
  7. explicitIntent.putExtra("systemName", systemName);
  8.  
  9.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


thanks for hints!
User avatar
E-Nature
Experienced Developer
Experienced Developer
 
Posts: 93
Joined: Mon Nov 16, 2009 3:39 pm

Top

Postby grzegorz.zajac » Wed Jan 06, 2010 4:13 pm

Hello,

It is possible by 2 different approaches:

1) your class implements the Serializable interface and you call the below method on the Intent object:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. putExtra(String name, Serializable value)
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


2) your class implements the Parcelable interface and you call:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. putExtra(String name, Parcelable value)
Parsed in 0.043 seconds, using GeSHi 1.0.8.4


Personally, I think that 1) is much easier to use, as the Serializable interface requires only 2 simple methods to be implemented.

Regards,
Grzesiek
grzegorz.zajac
Developer
Developer
 
Posts: 39
Joined: Wed Feb 18, 2009 8:37 pm
Location: Krakow/Poland

Postby E-Nature » Wed Jan 06, 2010 4:27 pm

that looks pretty simple! I'll try it out!
thanks :)
User avatar
E-Nature
Experienced Developer
Experienced Developer
 
Posts: 93
Joined: Mon Nov 16, 2009 3:39 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 9 guests