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

  • Home
  • SEARCH
  • 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 8053713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:56:29+00:00 2026-06-05T07:56:29+00:00

I have this code: public static final String PREFS_NAME = MyPrefsFile; public void onCreate(Bundle

  • 0

I have this code:

public static final String PREFS_NAME = "MyPrefsFile";

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

settings = getSharedPreferences(PREFS_NAME, 0);
boolean hasLoggedIn = settings.getBoolean("hasLoggedIn", false);

    if (!((LoginButton.email).equals(""))) {

        //settings = getSharedPreferences(PREFS_NAME, 0);
        SharedPreferences.Editor editor = settings.edit();
        // Set "hasLoggedIn" to true
        editor.putBoolean("hasLoggedIn", true);
        // Commit the edits!
        editor.commit();
        Log.d("hasLoggedIn in email check = ", hasLoggedIn + "");
    }
}

even after entering the if, the last Log gives me hadLoggedIn as false.

Somewhere in the same activity i got the same code of editing which works fine, but the only difference is i never used it as soon as it got edited, i used it when the activity is called again.

  • 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-05T07:56:31+00:00Added an answer on June 5, 2026 at 7:56 am

    You will again have to open sharedpreference for reading.

    your hasLoggedIn still contains old value.

    I have updated your code as below.

    public static final String PREFS_NAME = "MyPrefsFile";
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
    settings = getSharedPreferences(PREFS_NAME, 0);
    boolean hasLoggedIn = settings.getBoolean("hasLoggedIn", false);
    
        if (!((LoginButton.email).equals(""))) {
    
            //settings = getSharedPreferences(PREFS_NAME, 0);
            SharedPreferences.Editor editor = settings.edit();
            // Set "hasLoggedIn" to true
            editor.putBoolean("hasLoggedIn", true);
            // Commit the edits!
            editor.commit();
    
            //You forgot write following line.
            hasLoggedIn = getSharedPreferences(PREFS_NAME, 0).getBoolean("hasLoggedIn", false); 
            Log.d("hasLoggedIn in email check = ", hasLoggedIn + "");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have this code: public static void main(final String [] args) {
Say, I have a code snippet like this: public static void main(String[] args) {
I have this code fragment: public static class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean> {
I have this following test code: public static final String[] list = { apple,ball,cat,dog,egg,fan,girl,hat,igloo,jerk
I have this bit of code, public static List<string> GetSentencesFromWords(List<string> words, string fileContents) {
I have the following code: public static void Send(this MailMessage email) { if (!isInitialized)
I have this code: public void onPlayerInteract(PlayerInteractEvent event) { final Action action = event.getAction();
I have this code: public static final <TypeVO extends BaseVo> List<SelectItem> populateSelectBoxForType( final Class<TypeVO>
I have a question about the following code: public Class Settings{ public static final
I have the following (Java) code: public class TestBlah { private static final String

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.