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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:05:25+00:00 2026-06-10T23:05:25+00:00

Here is my code: mPrefs = getSharedPreferences(facebook_session,MODE_PRIVATE); String access_token = mPrefs.getString(access_token, null); long expires

  • 0

Here is my code:

    mPrefs = getSharedPreferences("facebook_session",MODE_PRIVATE);
    String access_token = mPrefs.getString("access_token", null);
    long expires = mPrefs.getLong("access_expires", 0);

    if(access_token != null) {
        facebook.setAccessToken(access_token);
        Log.i("access_token","facebook.setAccessToken(access_token), and access_token=="+access_token);

    }
    if(expires != 0) {
        Log.i("expires","facebook.setAccessToken(access_token), and expires=="+expires);
        facebook.setAccessExpires(expires);
    }


    /*
     * Only call authorize if the access_token has expired.
     */

    if(!facebook.isSessionValid()) {
    Log.v("in !facebook.isSessionValid()", "no pref");

    facebook.authorize( this, new String[] { "email", "publish_checkins" }, new DialogListener(){
        @Override
        public void onComplete(Bundle values) {
            Log.v("facebook.authorize", "no pref");
            Log.v("postToWall","mFacebook.getAccessToken(): "+facebook.getAccessToken());
            Log.v("postToWall","mFacebook.getAccessExpires(): "+facebook.getAccessExpires());

            SharedPreferences.Editor editor = mPrefs.edit();
            editor.putString("access_token", facebook.getAccessToken());
            editor.putLong("access_expires", facebook.getAccessExpires());
            editor.commit();

        }
        @Override
        public void onFacebookError(FacebookError e) {
            Log.v("facebook.authorize","mFacebook.onFacebookError(): "+e);
        }
        @Override
        public void onError(DialogError e) {
            Log.v("facebook.authorize","mFacebook.onFacebookError(): "+e);
            Log.v("facebook.authorize","mFacebook.onError(): "+facebook.getAccessToken());
        }
        @Override
        public void onCancel() {
            Toast.makeText(getApplicationContext(),
                    "You must be registered and signed in to perform that action",
                    Toast.LENGTH_LONG).show();
            finish();
            // onCancel, leaving the app
        }
    });   
    }//end of pref check

and in the logout function, I tried to logout form facebook and clear the sharedPreferences as well:
public void Logout(View view){

      String access_token = mPrefs.getString("access_token", null);
      Log.i("access_token","mPrefs.getString(access_token, null), and access_token=="+access_token);

      SharedPreferences.Editor editor = mPrefs.edit();
      editor.remove("access_token");
      editor.remove("access_expires");
      editor.commit();
      Log.i("access_token","mPrefs.getString(access_token, null), and access_token=="+access_token);

      mAsyncRunner = new AsyncFacebookRunner(facebook); // initialize AsyncRunner, make sure it's not null
      mAsyncRunner.logout(Login.this, new RequestListener() {
          @Override
          public void onComplete(String response, Object state) {
              finish();
          }

          @Override
          public void onIOException(IOException e, Object state) {}

          @Override
          public void onFileNotFoundException(FileNotFoundException e,
                Object state) {}

          @Override
          public void onMalformedURLException(MalformedURLException e,
                Object state) {}

          @Override
          public void onFacebookError(FacebookError e, Object state) {}
        });
  }

So, here is the question: No matter how hard I try, the values stored in sharedPreferences didn’t change. I tried clear(), remove(), commit(), apply() etc…..
Please help!

  • 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-10T23:05:27+00:00Added an answer on June 10, 2026 at 11:05 pm
      Log.i("access_token","mPrefs.getString(access_token, null), and access_token=="+access_token);
    

    If you are using this Log statement to verify whether the values stored in SharedPreferences are cleared or not, you are not doing it correctly.

    Your value access_token was assigned a value before you removed it, so when you reference the variable it will still retain that value. To correctly test whether the value has been removed from SharedPreferences, you need to try accessing that value again after you’ve removed it by doing the following after your editor.commit() command:

    String access_token_2 = mPrefs.getString("access_token", null);
    Log.i("access_token", "access_token from SharedPreferences is now " + access_token_2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is code for regular expression matching #include<iostream> #include<stdio.h> #include<string.h> using namespace std; int
I'm trying to match this block here /code\ int foo(string $bar, int $bleh); Simple
The script is on jsfiddle here : CODE What it does at the moment
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here is code my jqgrid editing through form. $(#DataEnergy).jqGrid('navGrid', '#pagergrid', {}, //options {editdata: {
Here my code, I need to insert into mysql database I have mysql,php,android 1)
Here is code from MSDN . I don't understand why the work isn't just
Here a code to demonstrate an annoying problem: class A { public: A(): m_b(1),
Here is code example class A{ int i; public: A(int i) : i(i) {}
My code here works fine to get the content length, and tells me how

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.