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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:39:35+00:00 2026-06-08T13:39:35+00:00

I have finished making an app. But I have some text in a sharedpreferences

  • 0

I have finished making an app. But I have some text in a sharedpreferences activity, and when the app starts it should pull it from there and insert it into an edittext, but if the app is fully closed, or the phone rebooted it doesn’t work and the default value is used instead.

Could anyone tell me why this is? And what data you would need.

Below is the main activity.

package com.liamwli.smsbusy;

import android.app.Activity;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.content.IntentFilter;
import android.content.SharedPreferences;

public class Sms_busyActivity extends Activity {
    IntentFilter intentFilter;
    ToggleButton endis;
    EditText message;
    Button smessage;
    SharedPreferences getPrefs;
    SharedPreferences.Editor editor;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Intent i = new Intent("com.liamwli.smsbusy.PREFS");
        // startActivity(i);
        setContentView(R.layout.main);

        endis = (ToggleButton) findViewById(R.id.enableddis);

        smessage = (Button) findViewById(R.id.savemess);

        message = (EditText) findViewById(R.id.message);

        getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

        editor = getPrefs.edit();

        // ---intent to filter for SMS messages received---
        intentFilter = new IntentFilter();
        intentFilter.addAction("SMS_RECEIVED_ACTION");

        Boolean state = getPrefs.getBoolean("enabled", false);

        String stext = getPrefs.getString("text", "");

        message.setText(stext);

        if (message.getText().toString().contentEquals("")){
            Toast.makeText(this, "Unable to get saved message. Please resave.", Toast.LENGTH_LONG).show();
        }

        endis.setChecked(state);

        endis.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // TODO Auto-generated method stub

                Log.d("SMS Busy App", "onCheckedChanged Called");

                //Toast.makeText(Sms_busyActivity.this, "App state changed",
                        //Toast.LENGTH_LONG).show();
                if (endis.isChecked()){
                    editor.putBoolean("enabled", true);
                    editor.commit();
                }else {
                    editor.putBoolean("enabled", false);
                    editor.commit();
                }

                editor.putString("message", message.getText().toString());
                editor.commit();

            }
        });

        smessage.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                editor.putString("message", message.getText().toString());
                editor.commit();
                Toast.makeText(Sms_busyActivity.this, "Message Saved", Toast.LENGTH_SHORT).show();
                Log.d("smessage", "Message saved & commited");

            }
        });

    }

    @SuppressWarnings("deprecation")
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (Integer.parseInt(android.os.Build.VERSION.SDK) < 5
                && keyCode == KeyEvent.KEYCODE_BACK
                && event.getRepeatCount() == 0) {
            Log.d("SMS Busy App", "onKeyDown Called");
            onBackPressed();
        }

        return super.onKeyDown(keyCode, event);
    }

    public void onBackPressed() {
        Log.d("SMS Busy App", "onBackPressed Called");

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // TODO Auto-generated method stub
        return super.onCreateOptionsMenu(menu);
    }

}
  • 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-08T13:39:37+00:00Added an answer on June 8, 2026 at 1:39 pm

    The problem is that you are using the same Editor for every call, and committing it more than once. This will only save the most recent change throughout the entire application.

    Try this:

                editor = getPrefs.edit();
                if (endis.isChecked()){
                    editor.putBoolean("enabled", true);
                }else {
                    editor.putBoolean("enabled", false);
                }
                editor.putString("message", message.getText().toString());
                editor.commit();
    

    And adjust your other commit code in the same manner.

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

Sidebar

Related Questions

I have some sort of evaluating application in the making, it's almost finished but
I have just finished ridding my project of leaks, but there are still thousands
I have an app that is nearly finished but encountered an annoying problem. In
I've just finished making some updates for a company's Android app, only to realize
I have finished developing a big and heavy app. It is universal (for iPhone
I have finished the development of my app which uses Google Maps. During the
*Hey , I have finished developing my app In my iphone apps I have
I have just finished creating an API where the requests from the API are
I have nearly finished a free spellchecker library for Windows Mobile, and there are
I have just finished creating an entire login and register systsem in PHP, but

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.