-1

I'm currently developing an android application that makes use of Google Places API.

I have 2 activities that I want to pass a variable between. I have tried passing by Intent using putExtras and getExtras.

I have been having issues with the getExtras. I have debugged my code, used breakpoints and an output of the variable to the log.

Here is my code for the activity of which I want to pass the variable from:

   Intent mapIntent = new Intent(getBaseContext(), MapsActivity.class);

   Spinner distanceSpinner = (Spinner) findViewById(R.id.spinner_distance);

   String radius = distanceSpinner.getSelectedItem().toString();

   mapIntent.putExtra("radius", radius);

   Log.e("Passer", String.valueOf(radius)); //Shows that value is not = null.

   startActivity(mapIntent);

The log out put for this class is correct and displays the variable.

Here is the code for my class that I want to pass the variable to:

Intent filterIntent = new Intent(getBaseContext(), LocateFilterActivity.class);

Bundle bd = filterIntent.getExtras();
String radius= (String) bd.get("radius");

Log.e("TESTER", String.valueOf(radius));

startActivity(placeIntent);

The log does not actually output anything for this class. I know it can reach and execute the line of code through debugging.

I have tried coding this several different ways following previous SO questions/answers but not having much luck.

Any help would be much appreciated :)

lou2216
  • 21
  • 4
  • you are trying to access wrong intent data – Rustam Apr 12 '16 at 09:06
  • Possible duplicate of [Using intents to pass data between activities in android](http://stackoverflow.com/questions/19286970/using-intents-to-pass-data-between-activities-in-android) – Miguel Benitez Apr 12 '16 at 09:06
  • try `getIntent().getStringExtra("radius");` in your `LocateFilterActivity` activity `onCreate()` method. – Rustam Apr 12 '16 at 09:07

1 Answers1

0

You can access data which were passed to an activity with getIntent().getExtras() method which you can call in a newly created activity that you have created with startActivity(intent) call. :)