Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4020734
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:15:54+00:00 2026-05-20T10:15:54+00:00

in my application user can create an array of elements.E.g. he can assign a

  • 0

in my application user can create an array of elements.E.g. he can assign a name of Array1 to Array2. My problem is that every time i launch the app, the Array2 arraylist is empty.
I define the array like this:

ArrayList<String> Array2 = new ArrayList<String>();

and this how i populate the arraylist:

Array2.add(strBuf.toString()); //strBuf is StringBuffer created from two strings

Do i miss something or should i save to array to a file or sg else?

Update:

I have two spinners and an OK button in a dialog. When user selects items from the spinners and clicks OK, an element is add the arraylist. This is done by concatenating two strings, one for the 1st spinner, one for the second (linkname1 and linkname2).
At first when the arraylist is empty, the item is added. When there is at least one item in the arraylist, there is a verification whether the item is already in the arraylist. If it is, it is overwritten, if not, it is added.

Button okbtn = (Button) dialog.findViewById(R.id.ButtonOK);
                okbtn.setOnClickListener(new View.OnClickListener() 
                {
                    public void onClick(View v) 
                    {
                        if ((linkname1!="") && (linkname2!=""))
                        {
                            strBuf = new StringBuffer();
                            strBuf.append(linkname2); 
                            strBuf.append(" ");
                            strBuf.append(linkname1); 


                            if (Array2.size() < 1)
                            {
                                Array2.add(strBuf.toString()); 
                            }
                            else if (Array2.size() > 0)
                            {
                              for (int i=0; i<Array2.size(); i++)
                              {
                                spaceIndex4 =  Array2.get(i).indexOf(' ');
                                if (spaceIndex4 > 0)
                                {
                                    if (linkname1.equals(Array2.get(i).substring(spaceIndex4+1, Array2.get(i).length()))==true)
                                    {
                                        van=1;
                                        Array2.remove(i);
                                        Array2.add(strBuf.toString());
                                    }
                                    else
                                    {
                                        van=2;
                                    }
                                }
                              }
                            }

                            }

                        dialog.dismiss();
                        if (van == 2)
                        {
                            Array2.add(strBuf.toString());
                        }
                    }
                });     

I use the items in the Arraylist later (when user clicks on specific items of a ListView, items of this ArrayList should appear).
When i quit the app, both in Eclipse and on my phone, and then open it again, the arraylist is empty (so the items are not appearing anymore when user clicks on an item of the ListView).
There is no Array2.clear() or such in the code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:15:55+00:00Added an answer on May 20, 2026 at 10:15 am

    Your ArrayList is just a variable. Variables die once the program closes, in any programming environment. You need to save your items somewhere permanent. Write it out to a file, or depending on how much you need to store, you can use SharedPreferences. Then just read it back in and repopulate the ArrayList in onCreate().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that shows a list of items. The user can click
I have a Timestamp value that comes from my application. The user can be
I have a web application with users and their documents. Each user can have
In a web application I am working on, the user can click on a
How can I dismiss dialog in Cocoa application when user presses Esc or Enter
How can I find out, which keyboard layout the user of my ruby application
I have an application (writted using Delphi 2009) that allows a user to run
We have a current application where user login credentials are stored in a SQL
I've got a multi-user application having some critical data of the users. I am
For part of a web application the user needs to import some data from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.