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 7071999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:45:18+00:00 2026-05-28T05:45:18+00:00

I have an Activity which lets the user input names and the save them.

  • 0

I have an Activity which lets the user input names and the save them. Once the add Button is clicked the name gets added to the Array and also shown in a ListView with an option to remove a name.

My question is I am trying to get to the point where if the user leaves the Activity then comes back to the Activity the Array and ListView will have been saved so there is no need to input all the names again. At the moment once the Activity is left and then come back to the Array and ListView are empty.

As you can see at the bottom I have tried to use onSaveInstanceState and onRestoreInstanceState but can’t get them to work can anyone expand on this code?

ArrayList<String> playerList = new ArrayList<String>();
ListView employeeList;
ArrayAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.addremove);

final MyAdapter adapter = new MyAdapter(this, R.layout.listview_content, playerList);
ListView employeeList = (ListView) findViewById(R.id.namelistview);
employeeList.setAdapter(adapter);



Button confirm = (Button) findViewById(R.id.add);
confirm.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText playername = (EditText) findViewById(R.id.userinput);
playerList.add(playername.getText().toString());
adapter.notifyDataSetChanged();
playername.setText("");

}});

Button play = (Button) findViewById(R.id.playnow);
play.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent( demo.AddRemove.this, demo.PasswActivity.class);
intent.putStringArrayListExtra("KEY", playerList);
startActivity(intent);

}});
}
class MyAdapter extends ArrayAdapter<String>{
    private OnClickListener listener; 
    public MyAdapter(Context context, int textViewResourceId, ArrayList<String> objects) {
        super(context, textViewResourceId, objects);
        listener = new OnClickListener(){
            public void onClick(View v){
            playerList.remove(v.getTag());
            notifyDataSetChanged();

            };
            };
            }


    public View getView(int position, View convertView, ViewGroup parent) {
        if( convertView== null ) convertView = getLayoutInflater().inflate(R.layout.listview_content, null);

        TextView myTextView1 = (TextView)convertView.findViewById(R.id.playername);
        myTextView1.setText(getItem(position)); 
        Button remove = (Button)convertView.findViewById(R.id.remove);
        remove.setTag(getItem(position));
        remove.setOnClickListener(listener);
        return convertView;
    }
}

 @Override
 public void onSaveInstanceState(Bundle outState) {
   // Save UI state changes to the savedInstanceState.
   // This bundle will be passed to onCreate if the process is
   // killed and restarted.
     outState.putStringArrayList("Playlist", playerList );

    super.onSaveInstanceState(outState); }


    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
      super.onRestoreInstanceState(savedInstanceState);
      // Restore UI state from the savedInstanceState.
      // This bundle has also been passed to onCreate.
        playerList = savedInstanceState.getStringArrayList("Playlist");


    }

}

  • 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-28T05:45:19+00:00Added an answer on May 28, 2026 at 5:45 am

    Have you try making your playerList as

     static
    

    it will solve your purpose

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

Sidebar

Related Questions

I have a couple of tables which are used to log user activity for
I have an Activity which when clicking the menu and a button appearing there,
I have Activity A which calls B, at which point let's say the user
I have an application which consists 3 activities - lets call them A, B
I have an activity that lets a user upload a photo to the web
Assume I have an Activity which contains two FrameLayouts (let's call them FrameA and
I have an activity which shows some List entries. When I click on a
I have created an activity which sends a number of notifications to status bar.
Say if I have a locationManager(LM) object in activity A, which is my main
I have an activity that contains several user editable items (an EditText field, RatingBar,

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.