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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:41:16+00:00 2026-05-23T07:41:16+00:00

I am using the code for remember my username and password. i have tried

  • 0

I am using the code for remember my username and password. i have tried a lot of hours for the code for remember my username name and password but i cant success in it.

Here is my code which i have download from internet but it didn’t work for me.

I have declared this variable in the extends activity.

public static final String PREFS_NAME = "MyPrefsFile";
public static final String PREFS_USER = "prefsUsername";
public static final String PREFS_PASS = "prefsPassword";

after that I have also declare different variable like below.

public String PREFS_USERS;
public String PREFS_PASS;

String username;
String upass;

and in the click listener i have given the following code.

SharedPreferences pref = getSharedPreferences(PREFS_NAME,MODE_PRIVATE);   

username = etUsername.getText().toString();
upass = etPassword.getText().toString();

getSharedPreferences(PREFS_NAME, MODE_PRIVATE)
    .edit()
    .putString(PREFS_USERS, username)
    .putString(PREFS_PASS, upass)
    .commit();

and at the time at retry i have return the following code in the oncreate activity to retry my user name and password.

SharedPreferences pref = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);

username = pref.getString(PREFS_USERS, "");
upass = pref.getString(PREFS_PASS, "");

But when I run the application i cant get the username and password.First time when i load the application i checked the remember me check box after log in and log out back from the application and close the application and when come back to it.it was not saved for me.

  • 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-23T07:41:17+00:00Added an answer on May 23, 2026 at 7:41 am

    The problem is in declaring the variables

    you have declared

    public static final String PREFS_NAME = "MyPrefsFile";
    public static final String PREFS_USER = "prefsUsername";
    public static final String PREFS_PASS = "prefsPassword";
    
    public String PREFS_USERS;
    public String PREFS_PASS; //assigned null here
    

    .putString(PREFS_PASS, upass) //here value of PREFS_PASS is null

    Use the following code

    better do like the folowing

    public String PREFS_USERNAME= "prefsUsername";
    public String PREFS_PASSWORD="prefsPassword";
    

    Store the data as using following code

    SharedPreferences pref = getSharedPreferences(PREFS_NAME,MODE_PRIVATE);   
    
    passwordInString = password.getText().toString();
    userNameInString = username.getText().toString();
    
    getSharedPreferences(PREFS_NAME, MODE_PRIVATE)
        .edit()
        .putString(PREFS_USERNAME, userNameInString)
        .putString(PREFS_PASSWORD, passwordInString)
        .commit();
    

    retrieve the data like the following

    SharedPreferences pref = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
    
    String usernameName = pref.getString(PREFS_USERNAME, "");
    String upassWord = pref.getString(PREFS_PASSWORD, "");
    

    Thanks
    Deepak

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

Sidebar

Related Questions

I'm using C# to log on a website. I have a helpful code sample
I'm trying to implement a remember me feature using ASP.NET MVC. It uses a
I'm writing a web app using grails and spring-security 3.0.3 which requires me to
I create a database using ADO.NET SQL queries like this: create database mydatabase create
i try to bind data to model with Html.EditorFor() helper and submit, but model
I'm trying to implement search code in my CoreData-based iPhone app. I'm not sure
Context: Asp.Net MVC3 w/Razor I am trying to put a login form on a
am having game with 10 levels. i want to change the second level lock
I'm having trouble adding the nice shadow on focus for an input box on
Every time I put an inline tag on the link's href attribute it somehow

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.