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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:21:39+00:00 2026-06-04T10:21:39+00:00

I am writing an app to save password with a login interface. The user

  • 0

I am writing an app to save password with a login interface. The user can change the login password. First time, I use the following code to save the password, so that the password will not reset when the app relaunch:

@Override
public void onSaveInstanceState(Bundle savedInstanceState){
    savedInstanceState.putString("pwd", currentPwd);
    super.onSaveInstanceState(savedInstanceState);
}

@Override
public void onRestoreInstanceState(Bundle savedInstanceState){
    currentPwd = savedInstanceState.getString("pwd");
}

But after I asked that, someone in this website suggested me to use “SharedPreferences”. So, I changed the code as follow:

@Override public void onCreate(Bundle savedInstanceState) {     
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);
    SharedPreferences settings = getSharedPreferences("setting", 0);
    currentPwd = settings.getString("pwd", "abc");
}

@Override public void onStop(){
    super.onStop();
    SharedPreferences settings = getSharedPreferences("setting", 0);
    SharedPreferences.Editor editor = settings.edit();
    editor.putString("pwd", currentPwd);
    editor.commit();
} 

After my experiment, I found that the password will be reset after one hour which the same as the first code. Have I changed it wrong for the second code? Or there are any suggested way to solve it? Thank you.

  • 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-04T10:21:41+00:00Added an answer on June 4, 2026 at 10:21 am

    Not sure I’m following your code, but here is how I would do this:

    To get password:

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    sp.getString("pwd", "abc");
    

    To set password:

    SharedPreferences.Editor editor = sp.edit();
    editor.putString("pwd", currentPwd);
    editor.commit();
    

    Hope that helps

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

Sidebar

Related Questions

I am writing an app to save password with a log in interface. The
We are writing an app that will use T4 to generate Flex/Actionscript to compile
Im writing a ruby application that can post comments on behalf of the user
Writing an iPhone app in which I want to save the user the grief
I'm simply trying to create a secure user file that will save basic login
I'm writing an app that contains the following tables: (1) employee_type, (2) employee and
I am writing an Android app which can take pictures and save them on
I am writing a first iOS app.. It's just getting user input and sending
I'm writing a simple app that takes standard input from the user. As for
In my app that I'm writing, I am use Core Data for persistent store.

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.