Hi, I am trying to send data from one activity to another activity using this method: how to retrieve a Double value from one activity to another? Yet every time I open up my application it crashes as its because my code is in the onCreate:
double lat, longi;
Intent getLocation;
Bundle extras;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getLocation = this.getIntent();
extras = getLocation.getExtras();
lat = extras.getDouble("lat");
longi = extras.getDouble("longi");
but when I put it in a button instead It can't resolve this.getIntent();
public void getCoordinates(View view){
Button coordinates = (Button) findViewById(R.id.getCoordinates);
coordinates.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
getLocation = this.getIntent();
extras = getLocation.getExtras();
lat = extras.getDouble("lat");
longi = extras.getDouble("longi");
}
});
}
I would like to receive data either automatically or using a button. I am quite new in mobile computing so please don't roast me.