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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:10:20+00:00 2026-06-17T01:10:20+00:00

I have a bundle passed from one activity to another. That contains String n

  • 0

I have a bundle passed from one activity to another. That contains String n (the length is max 30), String ID and String color. I need to save these values to an ArrayList as an array (n, ID, color) and then to save ArrayList to androids memory. I was looking for a best way of doing that.. I’ve tried database but its to complicated for me at the moment and I don’t think I need such a complex thing. I’ve tried FileOutputStream (as it explained here: http://developer.android.com/guide/topics/data/data-storage.html#pref?) but it’s not working for me, probably because I’m doing something wrong. Do I actually need to create an arraylist of arrays or may be i could use arraylist of bundles, or any other way..? Whats the best way…? Please help..

Thanks every one…Was trying all this time but no luck.. I’m posting the code hoping that someone could give me a hand on that:

public class MainActivity extends Activity
{
String gotNotes;
String n;
String gotDOW;
String gotID;
public String clrs;
public String id;
public String nts;
String gotHour;
String gotColor;
TextView notes;
public static String FILENAME = "allevents";
String[] newevent;
String[] events;
SharedPreferences sharedPref;


  @Override
  public void onCreate(Bundle savedInstanceState) 
   {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



    Button settings = (Button)findViewById(R.id.settings);

    Bundle gotPackage = getIntent().getExtras();
    if (gotPackage != null){
    gotNotes = gotPackage.getString("AddedNote");
    if (gotNotes.equals(" "))
      {
        n = "Empty";
      }
    else 
        {
        n = gotNotes;
        }
    //gotDOW = gotPackage.getString("Day");
    //gotHour = gotPackage.getInt("Hour");
    gotID = gotPackage.getString("ID");
    gotColor = gotPackage.getString("color");

    initialize();

    }
    else{}



 settings.setOnClickListener(new OnClickListener()
    {
       public void onClick(View v)
         {
              Intent i = new Intent(v.getContext(),Settings.class);
              startActivityForResult(i,0);
         }

    });

 }

private void initialize() 
 {
    // TODO Auto-generated method stub
String[] newevent = {n, gotID, gotColor};

ArrayList<String[]> events = new ArrayList<String[]>();
events.add(newevent);

SharedPreferences sharedPref = this.getPreferences(Activity.MODE_PRIVATE);
SharedPreferences.Editor editor =     this.getPreferences(Activity.MODE_PRIVATE).edit();
editor.putString("yourKey", events.toString());
editor.commit();

String allData = sharedPref.getString("yourKey", null);
String[] playlists = allData.split(",");

  /* for (int number=0;number<events.lastIndexOf(sharedPref);number++)
   {

           notes = (TextView)findViewById(getResources().getIdentifier(playlists[number], getString(0), allData));
           notes.setText(number+1);


   }*/



    notes = (TextView)findViewById(getResources().getIdentifier(gotID,     "id",getPackageName()));
    notes.setText(n);
    notes.setGravity(Gravity.CENTER_HORIZONTAL);
    notes.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
    if (gotColor.equals("Blue")){
    notes.setBackgroundColor(Color.rgb(99, 184, 255));}else
    if(gotColor.equals("Green")){
    notes.setBackgroundColor(Color.rgb(189, 252, 201));}else
    if(gotColor.equals("Yellow")){
    notes.setBackgroundColor(Color.rgb(238, 233, 191));}else
    if(gotColor.equals("Grey")){
    notes.setBackgroundColor(Color.LTGRAY);}else    
    if(gotColor.equals("Aqua")){
    notes.setBackgroundColor(Color.rgb(151, 255, 255));}else
    if(gotColor.equals("White")){}

}



    @Override
public boolean onCreateOptionsMenu(Menu menu) 
{
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;

}

}
  • 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-17T01:10:21+00:00Added an answer on June 17, 2026 at 1:10 am

    Simply use SharedPreferences to save your application’s data.

    SharedPreferences sharedPref = activity.getPreferences(Activity.MODE_PRIVATE);
    SharedPreferences.Editor editor = activity.getPreferences(Activity.MODE_PRIVATE).edit();
    editor.putString("yourKey", yourArray.toString());
    editor.commit();
    

    To get your array as String do the following:

    String arrayString = sharedPref.getString("yourKey", null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an int/string(s) that is passed from one fragment to another. For each
I'm trying to pass a String array from one activity to another but when
I have an image that I have in my bundle resources that I need
I am developing an android application in which I have passed a string from
I need to pass an image from one view to another view.In the firstView
I have one activity/java file (Browsefile.java) that would obtain the absolute path of the
Lets say you have one main activity called main, and other sub-activities that do
I have to pass a string value from one view to a label in
I have to pass a buffer from one thread to another and I am
I have an Android activity that displays a list of log entries (using a

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.