bundle is set or not

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

bundle is set or not

Postby pedroteixeira07 » Sun Jun 20, 2010 12:49 am

Hello there,

Can anyone help me building a condition on where some snippet of code will just run if the a certain bundle b was set. Otherwise it will continue as a normal activity. I can't seem to structure this in my head so I can start.

Thank you very much
pedroteixeira07
Experienced Developer
Experienced Developer
 
Posts: 74
Joined: Sun Oct 18, 2009 6:06 pm
Location: Funchal

Top

Re: bundle is set or not

Postby pedroteixeira07 » Sun Jun 20, 2010 1:47 am

Or maybe I don't even need all this. I just have this issue:
My Activity z can be started either from activity X or activity Y.
If Z starts from X executes a snippet of code.. not having any values in a bundle.
If Z starts from Y executes a snippet of code also, using values passed on a bundle fromY.

I wonder if Z starts from X and the bundle is empty, will it give errors?

Thanks
pedroteixeira07
Experienced Developer
Experienced Developer
 
Posts: 74
Joined: Sun Oct 18, 2009 6:06 pm
Location: Funchal

Re: bundle is set or not

Postby padde » Sun Jun 20, 2010 2:04 am

Why does nobody use the online reference?!....

http://developer.android.com/reference/ ... mpty%28%29
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Re: bundle is set or not

Postby pedroteixeira07 » Sun Jun 20, 2010 7:47 pm

I tried:

Bundle b = getIntent().getExtras();
if (b.isEmpty()==false){

and is actually empty so it should skip the snippet of code after... but it gives me a nullpointerexception
pedroteixeira07
Experienced Developer
Experienced Developer
 
Posts: 74
Joined: Sun Oct 18, 2009 6:06 pm
Location: Funchal

Re: bundle is set or not

Postby padde » Sun Jun 20, 2010 9:23 pm

Test if b is null.

Bundle b = getIntent().getExtras();
if (b != null) { // y is calling } else { // x is calling }
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests