How to add values from MainActivity to list in SecondActivity
I have a problem with adding values to list which is in SecondActivity. In MainActivity I set text in EditText boxes and send to second class. For the first time values are adding, but when I back to previous activity and one more time set text and send it, values in the list are replaced, not added. Someone know what is the source of this problem?
java android list
add a comment |
I have a problem with adding values to list which is in SecondActivity. In MainActivity I set text in EditText boxes and send to second class. For the first time values are adding, but when I back to previous activity and one more time set text and send it, values in the list are replaced, not added. Someone know what is the source of this problem?
java android list
Maybe problem is with closing SecondActivity? I'm using finish(), is it right?
– newbieHere
Nov 11 at 16:18
Make that list static if you want to keep it
– Lucefer
Nov 11 at 16:31
How are you sending data?
– gratien asimbahwe
Nov 11 at 16:35
I don´t reccomend you pass the list from the bundle, because if your list is huge that throw an exception and your app crash, like @Lucefer say´s make static to keep it and set null when you don´t use it.
– Daniel Carreto
Nov 11 at 17:02
Ok gr8! I created static list and it works! Thank you so much
– newbieHere
Nov 11 at 19:54
add a comment |
I have a problem with adding values to list which is in SecondActivity. In MainActivity I set text in EditText boxes and send to second class. For the first time values are adding, but when I back to previous activity and one more time set text and send it, values in the list are replaced, not added. Someone know what is the source of this problem?
java android list
I have a problem with adding values to list which is in SecondActivity. In MainActivity I set text in EditText boxes and send to second class. For the first time values are adding, but when I back to previous activity and one more time set text and send it, values in the list are replaced, not added. Someone know what is the source of this problem?
java android list
java android list
edited Nov 11 at 17:12
Mostafa Arian Nejad
551418
551418
asked Nov 11 at 16:05
newbieHere
95
95
Maybe problem is with closing SecondActivity? I'm using finish(), is it right?
– newbieHere
Nov 11 at 16:18
Make that list static if you want to keep it
– Lucefer
Nov 11 at 16:31
How are you sending data?
– gratien asimbahwe
Nov 11 at 16:35
I don´t reccomend you pass the list from the bundle, because if your list is huge that throw an exception and your app crash, like @Lucefer say´s make static to keep it and set null when you don´t use it.
– Daniel Carreto
Nov 11 at 17:02
Ok gr8! I created static list and it works! Thank you so much
– newbieHere
Nov 11 at 19:54
add a comment |
Maybe problem is with closing SecondActivity? I'm using finish(), is it right?
– newbieHere
Nov 11 at 16:18
Make that list static if you want to keep it
– Lucefer
Nov 11 at 16:31
How are you sending data?
– gratien asimbahwe
Nov 11 at 16:35
I don´t reccomend you pass the list from the bundle, because if your list is huge that throw an exception and your app crash, like @Lucefer say´s make static to keep it and set null when you don´t use it.
– Daniel Carreto
Nov 11 at 17:02
Ok gr8! I created static list and it works! Thank you so much
– newbieHere
Nov 11 at 19:54
Maybe problem is with closing SecondActivity? I'm using finish(), is it right?
– newbieHere
Nov 11 at 16:18
Maybe problem is with closing SecondActivity? I'm using finish(), is it right?
– newbieHere
Nov 11 at 16:18
Make that list static if you want to keep it
– Lucefer
Nov 11 at 16:31
Make that list static if you want to keep it
– Lucefer
Nov 11 at 16:31
How are you sending data?
– gratien asimbahwe
Nov 11 at 16:35
How are you sending data?
– gratien asimbahwe
Nov 11 at 16:35
I don´t reccomend you pass the list from the bundle, because if your list is huge that throw an exception and your app crash, like @Lucefer say´s make static to keep it and set null when you don´t use it.
– Daniel Carreto
Nov 11 at 17:02
I don´t reccomend you pass the list from the bundle, because if your list is huge that throw an exception and your app crash, like @Lucefer say´s make static to keep it and set null when you don´t use it.
– Daniel Carreto
Nov 11 at 17:02
Ok gr8! I created static list and it works! Thank you so much
– newbieHere
Nov 11 at 19:54
Ok gr8! I created static list and it works! Thank you so much
– newbieHere
Nov 11 at 19:54
add a comment |
1 Answer
1
active
oldest
votes
try this in first activity:
String array = {"Hi", "there", "yeah"};
Intent goIntent = new Intent(this, NewAppActivity.class);
/*
* put extra with "array" as a key and the String with your values as the value to pass
* */
goIntent.putExtra("array", array);
startActivity(goIntent);
and in second activity:
Bundle extras = getIntent().getExtras();
if (extras != null) {
String array = extras.getStringArray("array");
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250573%2fhow-to-add-values-from-mainactivity-to-list-in-secondactivity%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
try this in first activity:
String array = {"Hi", "there", "yeah"};
Intent goIntent = new Intent(this, NewAppActivity.class);
/*
* put extra with "array" as a key and the String with your values as the value to pass
* */
goIntent.putExtra("array", array);
startActivity(goIntent);
and in second activity:
Bundle extras = getIntent().getExtras();
if (extras != null) {
String array = extras.getStringArray("array");
}
add a comment |
try this in first activity:
String array = {"Hi", "there", "yeah"};
Intent goIntent = new Intent(this, NewAppActivity.class);
/*
* put extra with "array" as a key and the String with your values as the value to pass
* */
goIntent.putExtra("array", array);
startActivity(goIntent);
and in second activity:
Bundle extras = getIntent().getExtras();
if (extras != null) {
String array = extras.getStringArray("array");
}
add a comment |
try this in first activity:
String array = {"Hi", "there", "yeah"};
Intent goIntent = new Intent(this, NewAppActivity.class);
/*
* put extra with "array" as a key and the String with your values as the value to pass
* */
goIntent.putExtra("array", array);
startActivity(goIntent);
and in second activity:
Bundle extras = getIntent().getExtras();
if (extras != null) {
String array = extras.getStringArray("array");
}
try this in first activity:
String array = {"Hi", "there", "yeah"};
Intent goIntent = new Intent(this, NewAppActivity.class);
/*
* put extra with "array" as a key and the String with your values as the value to pass
* */
goIntent.putExtra("array", array);
startActivity(goIntent);
and in second activity:
Bundle extras = getIntent().getExtras();
if (extras != null) {
String array = extras.getStringArray("array");
}
answered Nov 11 at 16:31
Tsur Yohananov
132
132
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250573%2fhow-to-add-values-from-mainactivity-to-list-in-secondactivity%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Maybe problem is with closing SecondActivity? I'm using finish(), is it right?
– newbieHere
Nov 11 at 16:18
Make that list static if you want to keep it
– Lucefer
Nov 11 at 16:31
How are you sending data?
– gratien asimbahwe
Nov 11 at 16:35
I don´t reccomend you pass the list from the bundle, because if your list is huge that throw an exception and your app crash, like @Lucefer say´s make static to keep it and set null when you don´t use it.
– Daniel Carreto
Nov 11 at 17:02
Ok gr8! I created static list and it works! Thank you so much
– newbieHere
Nov 11 at 19:54