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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:39:13+00:00 2026-05-25T17:39:13+00:00

I have made a shared preference activity that store the user settings, now i

  • 0

I have made a shared preference activity that store the user settings, now i want to get values in a activity or normal java class.please provide a solution or example i have already tried this code but failed.

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    SharedPreferences channel=this.getSharedPreferences(strFile, Context.MODE_PRIVATE);
    strChannel=channel.getString(keyChannel,"Default").toString();
    Toast.makeText(getApplicationContext(), strChannel, Toast.LENGTH_LONG).show();
}                     

in this code strfile for eg. com.android.pack.ClassName is SharedPreference Activity from values to be fetched, and keyChannel is key that is same in SharedPreference Activity.

Kindly provide the solution.

  • 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-25T17:39:13+00:00Added an answer on May 25, 2026 at 5:39 pm

    If you have a SharedPreferenceActivity by which you have saved your values

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String imgSett = prefs.getString(keyChannel, "");
    

    if the value is saved in a SharedPreference in an Activity then this is the correct way to saving it.

    SharedPreferences shared = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
    SharedPreferences.Editor editor = shared.edit();
    editor.putString(keyChannel, email);
    editor.commit();// commit is important here.
    

    and this is how you can retrieve the values.

    SharedPreferences shared = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
    String channel = (shared.getString(keyChannel, ""));
    

    Also be aware that you can do so in a non-Activity class too but the only condition is that you need to pass the context of the Activity. use this context in to get the SharedPreferences.

    mContext.getSharedPreferences(PREF_NAME, MODE_PRIVATE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For several applications I made for my current client I have shared user accounts.
I have a big project compiled into libProject.so-file (shared library), I made some modules
I have made a little app for signing up for an event. User input
I do wallpapers to andoid and I want that the user could choose options.
I have made a report that shows transactions in a certain time period for
I have a class that extends PreferenceActivity and shows the preference screen of my
I have made an iPad application. Now i have a requirement to upload any
I have a shared reporting dll that is used in both windows and web.
I have an Excel 2010 macro application that is made up of several workbook
I've made my share of 2D games on various platforms but I have never

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.