How to add values from MainActivity to list in SecondActivity












0














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?










share|improve this question
























  • 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
















0














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?










share|improve this question
























  • 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














0












0








0







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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












1 Answer
1






active

oldest

votes


















0














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");
}





share|improve this answer





















    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    0














    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");
    }





    share|improve this answer


























      0














      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");
      }





      share|improve this answer
























        0












        0








        0






        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");
        }





        share|improve this answer












        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");
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 16:31









        Tsur Yohananov

        132




        132






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini