Passing an integer between actions and intentions in Android always happens at zero / zero

I am trying to transfer two integers from my main page (latitude and longitude) to a second activity containing an instance of Google Maps that will place the marker on the lat and for a long time. My puzzle is that when I get the package in the Map_Page action, the integers that I passed are always 0, which is the default when they are Null. Does anyone see something incredibly wrong?

I have the following stored when the OnClick button is clicked.

Bundle dataBundle = new Bundle(); dataBundle.putInt("LatValue", 39485000); dataBundle.putInt("LongValue", -80142777); Intent myIntent = new Intent(); myIntent.setClassName("com.name.tlc", "com.name.tlc.map_page"); myIntent.putExtras(dataBundle); startActivity(myIntent); 

Then in my map_page action, I have the following in onCreate to get the data.

 Bundle extras = getIntent().getExtras(); System.out.println("Get Intent done"); if(extras !=null) { System.out.println("Let get the values"); int latValue = extras.getInt("latValue"); int longValue = extras.getInt("longValue"); System.out.println("latValue = " + latValue + " longValue = " + longValue); } 
+6
android eclipse android-intent android-activity bundle
source share
2 answers
 System.out.println("Let 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); 

In addition, this may be because you do not store the name Int in exactly the same way in all code. Java and Android SDKs are case sensitive

+13
source share

Geeklat,

In this case, you do not need to use the bundle.

Do it like this ...

 Intent myIntent = new Intent(); 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 get them using ...

 Bundle extras = getIntent().getExtras(); int latValue = extras.getInt("LatValue"); int longValue = extras.getInt("LongValue"); 
+22
source share

All Articles