'Send multiple values between two activities
Hi I´m just starting to learn how to use Android Studio. And I want to try to send the values of the choices the user makes from one activity to the other.
Solution 1:[1]
You can pass data like this(this is from SecondActivity):
Intent intent = new Intent(this, ThirdActivity.class);
intent.putExtra("EXTRA_SESSION_ID", sessionId);
startActivity(intent);
and than in ThirdActivity in onCreate method:
String sessionId = getIntent().getStringExtra("EXTRA_SESSION_ID");
Also, best practise is to have key "EXTRA_SESSION_ID" stored in public static variable so you have only one object
Solution 2:[2]
1.Change this to arraylist
String[] mackor_names = {
"Tonfisk Macka 30:-",
"Skagen Macka 35:-",
"Kyckling Macka 35:-",
"Curryröra Macka 30:-",
"Ost o Kalkon Macka 25:-",
"Köttbulle Macka 25:-",
"Falafel Macka 20:-"
};
ArrayList<String> list = new ArrayList<>();
list.add("Tonfisk Macka 30:-");
list.add("Skagen Macka 35:-"); ......
2.and then use
intent.putStringArrayListExtra("test",list);
3.and to get values
Intent intent=getIntent();
ArrayList<String> test = intent.getStringArrayListExtra("test");
Solution 3:[3]
//Create the bundle
Bundle bundle = new Bundle();
//Add your data from getFactualResults method to bundle
bundle.putString("VENUE_NAME", venueName);
//Add the bundle to the intent
i.putExtras(bundle);
Insead of array you can use bundle
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | EffectiveIvana |
Solution 2 | |
Solution 3 | EffectiveIvana |