how to retrieve the bundle from onCreate(bundle) method?

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

how to retrieve the bundle from onCreate(bundle) method?

Postby sommeralex » Wed Feb 27, 2008 12:20 am

Hello..


Maybe someone can bring light into my dark.. first, i thought if I start an Intent by

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Intent i = new Intent(thisContext, myClasstoStart.class);
  3.  
  4. i.putExtra("test.hello", "hello!");
  5.  
  6. startSubActivity(i, 123);
  7.  
  8.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


that myClasstoStart will have the Bundle Data in his onCreate method

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. onCreate(Bundle bundle){
  3.  
  4. }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


so, that i could get the data by
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. bundle.getString("test.hello");
  3.  
  4.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


but this didnt work. i had to make this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Bundle bundle2 = getIntent().getExtras();
  3.  
  4. bundle2.getString("test.hello");
  5.  
  6.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


why? who puts data to the onCreate Bundle if not my Intent?!

thx for any help..
alex
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Top

Postby cabernet1976 » Wed Feb 27, 2008 8:01 am

Hi sommeralex,

the Bundle parameter icicle is used to save data when the activity is being re-initialized after previous being shut down, and then this Bundle contains the data it most recently supplied in onFreeze().
Upload2Flickr's blog: http://upload2flickr.blogspot.com
cabernet1976
Senior Developer
Senior Developer
 
Posts: 154
Joined: Fri Nov 16, 2007 2:34 am
Location: China

Postby sommeralex » Wed Feb 27, 2008 8:48 am

thank you!
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Postby plusminus » Wed Feb 27, 2008 4:39 pm

Hello sommeralex,

for more information on the "Lifecycle of an Activity", have a look here:

:arrow: http://www.anddev.org/viewtopic.php?t=81

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 sommeralex » Wed Feb 27, 2008 5:31 pm

thx - i know this diagramm already - but this doesnt chance anything on the confusing use of onCreate.

i thought, if i CREATE it, onCreate will be called. THEREFORE, if i pack it through an Intent and give data to it, (putExtra-method) i could retrieve the information directly from the parameter which is passed through by onCreate(bundle)...

so far...
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Postby plusminus » Thu Feb 28, 2008 2:36 am

Hello sommeralex,

data packed to the Intent that starts an Activity can be grabbed with:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.getIntent().getExtras...
Parsed in 0.042 seconds, using GeSHi 1.0.8.4


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

Top

Postby sommeralex » Thu Feb 28, 2008 9:00 am

i know 8) but this is what i was wondering for. my natural approach was that i can grab it through the onCreate(bundle) parameter the same as in java by main(String[] args)
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 19 guests