In android: I'm trying to take data from one activity/screen to another.
Let's say I'm adding two numbers. I layout my first screen (xml) with 2 EditText views, a couple labels, and an 'OK' button. Now, I want to add the numbers that I've input into the EditText views. Let's say I input 2 and 2 (2 + 2 = 4).
Now, when I hit the 'OK' button, I want a new screen/activity to appear and simply show me the answer (4). Do I use global vars to do this? Any help would be appreciated.
First Activity
Intent myIntent = new Intent();
myIntent.putExtra("key", "value");
startActivity(myIntent);
New Activity
Intent myIntent = getIntent(); // this is just for example purpose
myIntent.getExtra("key");
Check out the different types you can use on the Android Dev Site
Note: If you're looking for a way of sharing an object/data globally then you could extend the Application class. Check out How to declare global variables in Android? (answer by Soonil)
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