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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:26:36+00:00 2026-06-12T15:26:36+00:00

I’m trying to store a user entry into an EditText field however when I

  • 0

I’m trying to store a user entry into an EditText field however when I exit the application it does not appear.

So for example a user types in his/her name and then exits the application. When the user returns and launches the Application the users name appears in the EditText field. However I can’t get this to work. I believe its to do with sharedPreferences but I’m not sure where I’m going wrong.

I’m quite new to android and java so finding this quite difficult. Any help would be much appreciated.

public class MainActivity extends Activity {
     public final static String EXTRA_FROM = "com.example.assignment1.FROM";


     @Override
        protected void onSaveInstanceState(Bundle outState)
        {
            super.onSaveInstanceState(outState);
            EditText emailFrom =(EditText) findViewById(R.id.editEmailFrom);
            String from = emailFrom.getText().toString();
            outState.putString(EXTRA_FROM, from);
        }

        @Override
        protected void onRestoreInstanceState(Bundle savedState)
        {

            EditText emailFrom =(EditText) findViewById(R.id.editEmailFrom);
            String from = savedState.getString(EXTRA_FROM);
            emailFrom.setText(from);

        }

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

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

    public void emailSend (View sendButton) 
    {
        Intent intent = new Intent(this,DisplayEmailActivity.class);

        EditText emailFrom =(EditText) findViewById(R.id.editEmailFrom);
        String from = emailFrom.getText().toString();
        intent.putExtra(EXTRA_FROM,from);

        SharedPreferences saveFrom = getSharedPreferences(EXTRA_FROM, MODE_PRIVATE);
        Editor editor = saveFrom.edit();
        editor.putString(EXTRA_FROM, from);
        editor.commit();

        String storedfrom = saveFrom.getString(EXTRA_FROM, from);
        emailFrom.setText(storedfrom);

        startActivity(intent);
    }

Second Activity

 public class DisplayEmailActivity extends Activity {

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

            Intent intent = getIntent();

            String from = intent.getStringExtra(MainActivity.EXTRA_FROM);
            TextView textFrom =(TextView)findViewById(R.id.displayEmailFrom);
            textFrom.setText(from);

        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_display_email, 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-12T15:26:37+00:00Added an answer on June 12, 2026 at 3:26 pm

    Ok, so after you store value in your EditText emailFrom, you have to save it in SharedPreferences like this:

    String from = emailFrom.getText().toString(); // Getting String value from EditText and storing it in "from" String
    SharedPreferences settings = getSharedPreferences("MyPreferencesFile", 0); // Opening SharedPreferences 
    SharedPreferences.Editor editor = settings.edit(); // Opening editor for SharedPreferences
    editor.putString("exampleName", from); // You are putting here a String "from" and give it a "exampleName" name. Later you will use this name to restore data.
    

    And then when you launch your application, you need to load data from SharedPreferences:

    SharedPreferences settings = getSharedPreferences("MyPreferencesFile", 0); // Again opening SharedPreferences
    String from = settings.getString("exampleName", ""); // The second argument is the default value. The default value will be set if there wasn't saved any data with "exampleName" name
    if(from != "") // If "from" is not empty, it means that the data was stored in SharedPreferences
       emailFrom.setText(from); // Setting text in your EditText
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

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.