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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:05:37+00:00 2026-06-15T15:05:37+00:00

I have an activity which saves some data using sharedpreferences as below : public

  • 0

I have an activity which saves some data using sharedpreferences as below :

public void birthDateSharedPreferences(int calculatedBirthYear, int calculatedBirthMonth, int calculatedBirthDay)
    {
      SharedPreferences birthDatePreferences = PreferenceManager.getDefaultSharedPreferences(this);
      SharedPreferences.Editor editor = birthDatePreferences.edit();
      editor.putInt("birthChosenDay",calculatedBirthDay);
      editor.putInt("birthChosenMonth",calculatedBirthMonth);
      editor.putInt("birthChosenYear",calculatedBirthYear);
      editor.commit();
      Toast.makeText(birthDate.this,"The date was saved", Toast.LENGTH_LONG).show();
      Intent saved = new Intent(birthDate.this,MenuActivity.class);
      startActivity(saved);
      finish();
}

here is the second activity

SharedPreferences prefs = getPreferences(MODE_PRIVATE); 
                   int birthChosenDay = prefs.getInt("birthChosenDay", MODE_APPEND);

and I have another activity in which I want to use the data I saved in the first activity ,
I searched and tried some codes but nothing worked ! so how could I use the data which was saved in the first activity into the second activity ?

  • 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-15T15:05:38+00:00Added an answer on June 15, 2026 at 3:05 pm

    In the second activity you should get the default shared preferences (the one used while saving)..

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    int birthChosenDay = prefs.getInt("birthChosenDay", MODE_APPEND);
    

    AS:

     PreferenceManager.getDefaultSharedPreferences(this);
    

    Will provide an access to a preferences file that is global for the whole application package ; any activity can access the preferences (internaly, the xml file holding the preferences will be named your.application.package_preferences.xml).

    getPreferences(Context.MODE_PRIVATE);
    

    Will provide preferences only for the contextInstance class: only instances of the context’s class can access these preferences (said your package is still your.application.package and you’re in your.application.package.SecondActivity, internaly the preferences file is SecondActivity.xml).

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

Sidebar

Related Questions

I have an activity which shows some List entries. When I click on a
I have an activity which is used for editing some object. Currently its layout
I have some 34 checkboxes on one Activity which i have to mark and
I have an activity that uses AsyncTask to download and save some data to
i have a listview in which i have some list of data i am
I have an activity which is going to switch around between several views, and
I have a activity which has a button and 2 autocomplete widget. for the
I have an Activity which shows a welcome message if started for the first
I have an activity which needs to make two remote server calls. The first
I have an activity which uses two Loaders. Each of them returns different type

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.