I have some variables that I want to pass to my next activity, but I can't figure a way to do that.
My variables are:
JSONObject jsonObj = jsonArray.getJSONObject(i);
String propId = jsonObj.getString("id");
Log.i("Value id", propId);
String propCity = jsonObj.getString("city");
Log.i("Value city", propCity);
String propPlace = jsonObj.getString("place");
Log.i("Value place", propPlace);
String propStation = jsonObj.getString("station");
Log.i("Value station", propStation);
and the code I used to get them is:
Bundle extras = new Bundle();
extras.putString("id", propId);
extras.putString("city", propCity);
extras.putString("place", propPlace);
extras.putString("station", propStation);
Can anyone help me with this please ?
The code you posted is to write them to the Bundle, after you write in the Bundle use .putExtras()
to put your bundle in your Intent
.
intent.putExtras(bundle);
Example:
Intent intent = new Intent(this, YourClass.class);
Bundle extras = new Bundle();
extras.putString("id", propId);
extras.putString("city", propCity);
extras.putString("place", propPlace);
extras.putString("station", propStation);
intent.putExtras(bundle);
startActivity(intent);
To read it in your activity use getExtras()
to get the Bundle
you passed to it and then use getString
/getXXX
.
Anyway, you can avoid the creation of the Bundle
and use directly the set methods of Intent
which works in the same way.
So it would be:
Intent intent = new Intent(this, YourClass.class);
intent.putExtra("id", propId);
intent.putExtra("city", propCity);
intent.putExtra("place", propPlace);
intent.putExtra("station", propStation);
startActivity(intent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With