ANDROID:PASSING THE VARIABLE DATA FROM ONE ACTIVITY TO ANOTHER THROUGH INTENT

This program is to pass the values v1 and v2 through intent to the next activity.

Transmitter side(MainActivity.java):
 
Double v1=10; 
Double v2=2; 
b2.setOnClickListener(new View.OnClickListener() { 
@Override public void onClick (View v){ 
Intent myIntent = new Intent(MainActivity.this, MapsActivity.class); 
myIntent.putExtra("value1",v1 ); 
myIntent.putExtra("value2",v2 ); 
startActivity(myIntent); 
} 
});

Receiver Side(MapsAcivity.java):

Intent mIntent = getIntent();
lat = mIntent.getDoubleExtra("value1", 0);
lon = mIntent.getDoubleExtra("value2", 1); 
Here we will receive the value v1 in lat fetching 0th position and v2 in lon fetching 1st position.

 

Leave a Reply

Your email address will not be published. Required fields are marked *