Bundles.... how to pass parameters into another activity

Put your problem here if it does not fit any of the other categories.

Bundles.... how to pass parameters into another activity

Postby bluefloyd8 » Tue Jan 29, 2008 12:44 am

Hello all.

I am making a map application. I want to call the map activity from another activity and pass string parameters into the map activity. I was going to use bundles. Ive tried some code to get them working and am completely lost.

Does anybody have some sample code on how to use bundles?


Here is what i tried:
List Activity:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         String s = "Hello world";
  2.  
  3.         Bundle extras = new Bundle();
  4.  
  5.         extras.putString("titles", s);
  6.  
  7.         Intent i = new Intent(this, ShowMap.class);
  8.  
  9.         i.putExtras(extras);
  10.  
  11.         startSubActivity(i, 0);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Map Activity:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onCreate(Bundle icicle) {
  2.  
  3.                 super.onCreate(icicle);
  4.  
  5.                 setContentView(R.layout.showmap_map);
  6.  
  7.                 Bundle example = icicle.getBundle("extras");
  8.  
  9.  
  10.  
  11.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


I guess my simplified question would be: What code do i need in my map activity to unpack the extras bundle and access the "hello world" string inside it?
User avatar
bluefloyd8
Experienced Developer
Experienced Developer
 
Posts: 70
Joined: Tue Jan 22, 2008 3:57 am
Location: Indiana, USA

Top

Postby plusminus » Tue Jan 29, 2008 1:16 am

Hello bluefloyd,

you do it liek this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         /* Retrieve the String from the Extra-Bundle
  2.  
  3.          * we put had put to the Intent in the Caller . */
  4.  
  5.         Bundle b = this.getIntent().getExtras();
  6.  
  7.         String s = b.getString("titles");
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Hope I could help you. :)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby bluefloyd8 » Tue Jan 29, 2008 2:14 am

Sweet. that worked perfectly. I knew it was something simple!
User avatar
bluefloyd8
Experienced Developer
Experienced Developer
 
Posts: 70
Joined: Tue Jan 22, 2008 3:57 am
Location: Indiana, USA

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 10 guests