Skip to content Skip to sidebar Skip to footer

Passing Integer Between Activities And Intents In Android Is Always Resulting In Zero / Null

I'm attempting to pass two integers from my Main Page activity (a latitude and longitude) to a second activity that contains an instance of Google Maps that will place a marker at

Solution 1:

Geeklat,

You don't need to use Bundle in this case.

Do your puts like this...

IntentmyIntent=newIntent();
myIntent.setClassName("com.name.tlc", "com.name.tlc.map_page");
myIntent.putExtra("LatValue", (int)39485000);
myIntent.putExtra("LongValue", (int)-80142777);
startActivity(myIntent);

Then you can retrieve them with...

Bundleextras= getIntent().getExtras();
intlatValue= extras.getInt("LatValue");
intlongValue= extras.getInt("LongValue");

Solution 2:

System.out.println("Let's get the values");
int latValue = extras.getInt("latValue");
int longValue = extras.getInt("longValue");

Not the same as

myIntent.putExtra("LatValue", (int)39485000);
myIntent.putExtra("LongValue", (int)-80142777);

Also it might be because you do not keep the name of the Int exactly the same throughout your code. Java and the Android SDK are Case-sensitive

Post a Comment for "Passing Integer Between Activities And Intents In Android Is Always Resulting In Zero / Null"