I am creating an application named e-wardrobe, users will fill some inputs such as "type of cloth", "season", "color". I want when user writes winter, for example, into the season field, the app will pass type and color strings, into the WinterActivity but i don't know how to do this. I hope you will help me, thanx in advance :)
Asked
Active
Viewed 48 times
-4
-
3have you search title in google at all? you will find many many sample code and tutorial. – Shayan Pourvatan Jan 06 '15 at 11:19
-
2did you even bother googling it ? search for `intent.putExtra` to get started. – Sufiyan Ghori Jan 06 '15 at 11:21
-
yes i did and i tried some things but they didn't work. :( – user3676303 Jan 06 '15 at 11:21
-
1then show us what you have tried, what problems are you facing ? show some errors and `code`, otherwise no one would help you. – Sufiyan Ghori Jan 06 '15 at 11:22
-
1please show the code that you have tried that is not working – LeMoN.xaH Jan 06 '15 at 11:22
3 Answers
0
you can check the season field then determine what Activity to start from that field and then place the other information you want to pass along with it inside the intent as a bundle. Or better yet dont make a winter activity just make a SeasonActivity and just pass in all the other information and then let the activity decide what it needs to look like and what data it should share with the user.
The data passing from A -> B is in an intent
but from A -> B(dialog or second step) -> is done via ActivityForResult

LeMoN.xaH
- 571
- 2
- 9
-
Its better to let the OP show some efforts before giving away the entire solution. – Sufiyan Ghori Jan 06 '15 at 11:24
-
1didn't give any code help :) just the theory. i will only ever help with code if they have code that they have written and need help with – LeMoN.xaH Jan 06 '15 at 11:30
0
You need to add bundle data to a launch intent like this
//create the intent and bundle
Intent launchIntent = new Intent(
MenuActivity.this, com.you.AnotherActivity.class);
Bundle extraData = new Bundle();
//assign some values to the bundle
extraData.putSerializable("key1", "value");
//assign bundle to launchIntent
launchIntent.putExtra("keyBundle", extraData);
//start the activity
startActivity(launchIntent);
Then retrieve the data in the other activity like this:
//create a new intent to put the one that started this activity
Intent intent = getIntent();
//retrieve the bundle that was sent in the intent
Bundle recievedBundle =
intent.getBundleExtra("keyBundle");
//get the bundle passed from the activity that started this one
MyVariableInAnotherActivity = recievedBundle.getSerializable("key1");

Tim Ashton
- 436
- 6
- 18
0
Try this:
Intent intent = new Intent(CurrentActivity.this, WinterActivity.class);
intent.putExtra("cloth", clothTextField.getText().toString());
intent.putExtra("color", colorTextField.getText().toString());
startActivity(intent);
In the Winter Activity you receive them like:
String cloth = getIntent().getStringExtra("cloth");
String color = getIntent().getStringExtra("color");
Hope it helps!!!

Kostas Drak
- 3,222
- 6
- 28
- 60