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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:50:02+00:00 2026-06-16T16:50:02+00:00

I’m new to Android and I don’t know how to retrive the values stored

  • 0

I’m new to Android and I don’t know how to retrive the values stored using sharedpreferences, I couldn’t find any example of what I have to write on the other activity to use these values. If someone can help me I would really appreciate it

This is how I am storing the data:

protected void onResume() {
    super.onResume();
    SharedPreferences prefs = getPreferences(0);
    String restoredText1 = prefs.getString("cpw", "30");
    if (restoredText1 != null) {
        savedcostperworker.setText(restoredText1, TextView.BufferType.EDITABLE);

        int selectionStart = prefs.getInt("selection-start", -1);
        int selectionEnd = prefs.getInt("selection-end", -1);
        if (selectionStart != -1 && selectionEnd != -1) {
            savedcostperworker.setSelection(selectionStart, selectionEnd);
        }
    }
}

protected void onPause() {
    super.onPause();
    SharedPreferences.Editor editor = getPreferences(0).edit();
    editor.putString("cpw", savedcostperworker.getText().toString());
    editor.putInt("selection-start", savedcostperworker.getSelectionStart());
    editor.putInt("selection-end", savedcostperworker.getSelectionEnd());
}

private EditText savedcostperworker;

Now I want to show the value “cpw” in a TextView in another activity, but I don’t know how

  • 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-16T16:50:03+00:00Added an answer on June 16, 2026 at 4:50 pm

    You forgot to call commit() to save your Editor changes:

    SharedPreferences.Editor editor = getPreferences(0).edit();
    ...
    editor.commit();
    

    Now I want to show the value “cpw” in a TextView in another activity, but I don’t know how

    Simply call getSharedPreferences() with the first Activity’s name and use it like before:

    SharedPreferences prefs = getSharedPreferences("MainActivity", 0);
    String string = prefs.getString("cpw", "String not found");
    Log.v("SharedPrefs", string);
    

    You cannot use getPreferences() in the second Activity because it will call getSharedPreferences() with the wrong file name. See getPreferences() documentation for more information.

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

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am using JSon response to parse title,date content and thumbnail images and place
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.