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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:18:20+00:00 2026-06-07T15:18:20+00:00

In my android application I want to be able to add a string value

  • 0

In my android application I want to be able to add a string value to a static arraylist I have declared on my main android activity. The logic goes like this:

1) When you click a button and an activity starts. On the oncreate method I want to save the name of the class that is the current activity to a string value. For example:

String className = "com.lunchlist.demo";

After this value is assigned I want to immediately add this string value to a Static ArrayList I have declared in my main android activity (meaning first android activity that starts) After adding the value

I did something like this:

static String List<String> members = new ArrayList<String>();

This is declared in my main activity. Now when I click a button to start another activity I use this to add the string classname for that current activity to my arraylist in my oncreate method:

  String className = "com.lunchlist.demo" 
  members.add(className);

My question is now, would this add the string value to my arraylist and save it for later use? For example If I click three different buttons this will add three different className values to the arraylist. Would this then store a string value that would hold three different string values for my members arraylist? How would I check each item in my arraylist to see if the values are being added when a new activity is started?

I’m asking this because I will need to retrieve this and store these values using shared preferences and later retrieve them and starting an intent using the string value which is the class to start the activity. I got the activity to start with a string value of a class name I’m just having trouble storing them.

  • 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-06-07T15:18:21+00:00Added an answer on June 7, 2026 at 3:18 pm

    Answering to all of your questions:

    would this add the string value to my arraylist and save it for later
    use?

    Yes. Your code seems perfect to do it with no problems.

    For example If I click three different buttons this will add three
    different className values to the arraylist. Would this then store a
    string value that would hold three different string values for my
    members arraylist?

    If you tell to your button’s onClickListener to add a string to the members ArrayList then it will be done and no matter if you already had previously added that member to the ArrayList because array lists don’t care if there is duplicated data or not.

    How would I check each item in my arraylist to see if the values are
    being added when a new activity is started?

    You have to iterate your array list with a for or a for-each cicle and then print that member name as a log entry.

    • For-each cicle

      for (String member : members){
          Log.i("Member name: ", member);
      }
      
    • Simple For cicle

      int listSize = members.size();
      
      for (int i = 0; i<listSize; i++){
          Log.i("Member name: ", members.get(i));
      }
      

    If you try to print/ log a value which index is out of range, i.e., i < 0 || i >= listSize then a IndexOutOfBoundsException will be thrown and crash your app.

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

Sidebar

Related Questions

I have a application requirement in Android. In my application I want to add
I'm writing an Android application that I want to be able to send requests
I want to create an application for Android that will be able to scan
I have an Android application with a Spinner and want to fill it dynamically
I'm developing Android application using third party libraries (Twitter4j). I want to be able
I want to add a non-native shared library to Android so every application on
I want to be able to play an mp3 file in my android application
In an Android application written in Java, I want to be able to turn
I use Ant to build my Android application. I want to be able to
I want from the android browser be able to launch my application if it's

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.