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

  • Home
  • SEARCH
  • 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 7618451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:24:28+00:00 2026-05-31T03:24:28+00:00

Using shared preferences I saved data in one of the activity Now I want

  • 0

Using shared preferences I saved data in one of the activity Now I want to use that data in another activity how to do that?

  • 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-31T03:24:30+00:00Added an answer on May 31, 2026 at 3:24 am

    PREFS_NAME is the value you stored in shared preference.

     public static final String PREFS_NAME = "MyPrefsFile";    
    
    // Restore preferences
       SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
       boolean silent = settings.getBoolean("silentMode", false)
    

    Look at Restoring preferences

    Edited:To use it among all classes i.e. setter getter method.Perfect use of OOPS.You can call the value from any class thats 1-line job

    Make a normal class name as ReturningClass.

    public class ReturningClass {
    
    private static String MY_STRING_PREF = "mystringpref";
    
    private static String MY_INT_PREF = "shareduserid";
    
    public static SharedPreferences getPrefs(Context context) {
    
    
        return context.getSharedPreferences("UserNameAcrossApplication", context.MODE_PRIVATE);
    
    }
    
    public static String getMyStringPref(Context context) {
    
        return getPrefs(context).getString(MY_STRING_PREF, "default");
    }
    
    public static int getMyIntPref(Context context) {
    
        return getPrefs(context).getInt(MY_INT_PREF, 0);
    }
    
    public static void setMyStringPref(Context context, String value) {
        // perform validation etc..
        getPrefs(context).edit().putString(MY_STRING_PREF, value).commit();
    }
    
    public static void setMyIntPref(Context context, int value) {
        // perform validation etc..
        getPrefs(context).edit().putInt(MY_INT_PREF, value).commit();
    }
    

    Set your value by calling

      ReturningClass.setMyIntPref(mContext,22);
    

    Once You have set your sharedPreference.Then just call this method.Just pass the context.from your class

     int usersharedpreference=ReturningClass.getMyIntPref(mContext);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that I can share files using Shared Folders in Virtual PC, but
Today we're using a shared SQL Server database and that is perfect as I
I am trying to share two different using one shared memory block using the
I want to delete the various information i have stored as shared preferences. I
I want to save images in android using SharedPreference. I have two activity classes,
I am using shared preferences to store the number of times my application has
Using a simple EditTextPreference in my preferences activity: <EditTextPreference android:key=SomeKey android:title=@string/some_title android:summary=... android:numeric=integer android:maxLength=2
I am using shared hosting with IIS7 and support for PHP. I am trying
Is an IPC mechanism using shared memory and semaphores for synchronization simplex like pipes
I need to execute a http web request from Plesk's Task Scheduler (using shared

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.