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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:20:57+00:00 2026-05-31T13:20:57+00:00

I have a notes app and basically i want it to save the text

  • 0

I have a notes app and basically i want it to save the text input and restore it when i return to the activity. But why isn’t my code doing that? I tried onRestoreInstancestate and onRestore but it’s not working. Any one know how i can save the text input after i exit the app?

notes.java:

public class notes extends Activity{




    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.notes);




        Button wg = (Button) findViewById(R.id.button3);
        wg.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent intent = new Intent();
                setResult(RESULT_OK, intent);
                finish();
            }   
        });

    }
} 
  • 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-31T13:20:57+00:00Added an answer on May 31, 2026 at 1:20 pm

    Ok here you have the working, tested code

    notes.java (src\izzy\n\notes.java)

    package izzy.n;
    
    import android.app.Activity;
    import android.content.Context;
    import android.content.SharedPreferences;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    
    // actually you should name the class "Notes" since it's convention
    // but it would proably cause errors since you have to rename the file then.
    public class notes extends Activity {
        public static final String DEFAULT_TEXT = "Write some text here";
        public static final String PREFS_KEY_TEXT = "text";
        public static final String PREFS_NAME = "MyPrefsFile";
    
        private EditText mEditText;
    
        /**
         * Loads the text from SharedPreferences
         */
        private String loadText() {
            SharedPreferences settings = getSharedPreferences(notes.PREFS_NAME,
                    Context.MODE_PRIVATE);
            return settings.getString(notes.PREFS_KEY_TEXT, notes.DEFAULT_TEXT);
        }
    
        /**
         * Saves text to SharedPreferences
         */
        private void saveText(String text) {
            SharedPreferences settings = getSharedPreferences(notes.PREFS_NAME,
                    Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(notes.PREFS_KEY_TEXT, text);
            editor.commit();
        }
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.notes);
    
            // when you click on the button the app will exit
            // you kind of don't need such a button :)
            Button wg = (Button) findViewById(R.id.exit_button);
            wg.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    finish();
                }
            });
    
            mEditText = (EditText) findViewById(R.id.edit_text);
    
            String savedText = loadText();
            mEditText.setText(savedText);
            // put the cursor to the end.
            mEditText.setSelection(savedText.length());
        }
    
        @Override
        protected void onStop() {
            super.onStop();
            saveText(mEditText.getText().toString());
        }
    
    }
    

    notes.xml (res\layout\notes.xml)

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <Button
            android:id="@+id/exit_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Exit" />
    
        <EditText
            android:id="@+id/edit_text"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:gravity="top"
            android:layout_weight="1"
            android:hint="Enter Text here"
            android:inputType="textMultiLine" />
    
    </LinearLayout>
    

    What you get

    how it looks

    PS: You should maybe start reading some basic Java tutorials since you seem to have problems with basics 🙂

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

Sidebar

Related Questions

I have two tables containing Tasks and Notes, and want to retrieve a list
Basically, I want my model to have its own validation logic while having the
I have an app which saves some data on a sqlite DB. Basically, I
basically I have a pivot control in my WP7 app that contains 3 views.
In the app that I'm developing, I want to have re-occuring task on each
i am building a webapp that will have notes fields all over the place,
I have multiple notes with class=.note and unique id each inside a div. On
I'm reviewing my old algorithms notes and have come across this proof. It was
I have a database with two main tables notes and labels . They have
I have an oc4j installation bereft of any release notes or version documentation. In

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.