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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:28:08+00:00 2026-05-25T10:28:08+00:00

This is how I retrieve the information stored in shared preference and later am

  • 0

This is how I retrieve the information stored in shared preference and later am comparing whether username and password exists. If user is logged in I am able to show another activity.

SharedPreferences settings = getSharedPreferences(“logindetails”, 0);

    String username = settings.getString("username", "");


    String password = settings.getString("password", "");

But now I am trying to retrieve the username and gender of the user and display in my activity.

I am trying to solve this, but not yet found the convincing result.

Can any one help me to get out of my requirement?

Note: I am also seeing the documents of Facebook developer’s page


This is the code I am using to retrieve the user data and display in another activity. What problem am facing is the layout is loaded before the response from the facebook is paresed. I suspect it is because of the use of mAsyncRunner as it takes the control on its own. What I am trying to find out is hwo to parse it before the layout is loaded.

public class FaceBookRetrieval extends Activity{


this.facebookConnector = new FacebookConnect(APP_ID, this,
                getApplicationContext(), PERMS);

}

public class FacebookConnect {

    public FacebookConnect fb = null;
    private Facebook facebook = null;
    private Context context;
    private String[] permissions;
    public static final String TAG = "FACEBOOK";
    private AsyncFacebookRunner mAsyncRunner;
    private SharedPreferences sharedPrefs;
    private ProgressBar pb;
    public  String fbName, fbGender;
    private Activity activity;
    public String check = "false";
    private SessionListener mSessionListener = new SessionListener();;

    public FacebookConnect(String appId, Activity activity, Context context,
            String[] permissions) {
        this.facebook = new Facebook(appId);
        mAsyncRunner = new AsyncFacebookRunner(facebook);
        SessionStore.restore(facebook, context);
        SessionEvents.addAuthListener(mSessionListener);
        SessionEvents.addLogoutListener(mSessionListener);

        this.context = context;
        this.permissions = permissions;
        this.activity = activity;
    }

    public void login() {
        if (!facebook.isSessionValid()) {
            facebook.authorize(this.activity, this.permissions,
                    new LoginDialogListener());
        }
    }

    public void getID() {

            login();


        return;
    }

    public boolean isSession() {
        sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
        String access_token = sharedPrefs.getString("access_token", "x");
        Long expires = sharedPrefs.getLong("access_expires", -1);
        Log.d(TAG, access_token);
        facebook.setAccessToken(null);
        facebook.setAccessExpires(-1);

        if (access_token != null && expires != -1) {
//          facebook.setAccessToken(access_token);
//          facebook.setAccessExpires(expires);



        }

        return facebook.isSessionValid();
    }



    // request the facebook to provide the response and then parse the response to 
    // obtain username and gender
    private class IDRequestListener implements RequestListener {

        @Override
        public void onComplete(String response, Object state) {
            try {

                Log.d(TAG, "Response: " + response.toString());
                JSONObject json = Util.parseJson(response);
                fbGender = json.getString("gender");
                fbName = json.getString("name");
                check = "true";

            } catch (JSONException e) {
                Log.d(TAG, "JSONException: " + e.getMessage());
            } catch (FacebookError e) {
                Log.d(TAG, "FacebookError: " + e.getMessage());
            }
            Toast.makeText(context, "hello", Toast.LENGTH_SHORT).show();
            FacebookConnect.this.runOnUiThread(new Runnable() {
                public void run() {
                    pb.setVisibility(ProgressBar.VISIBLE);
                }
            });
            return ;
        }

        @Override
        public void onIOException(IOException e, Object state) {
            Log.d(TAG, "IOException: " + e.getMessage());
        }

        @Override
        public void onFacebookError(FacebookError e, Object state) {
            Log.d(TAG, "FacebookError: " + e.getMessage());
        }

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

        }

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

        }

    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        facebook.authorizeCallback(requestCode, resultCode, data);
    }

    public void runOnUiThread(Runnable runnable) {
    }



    private class LoginDialogListener implements DialogListener {

        @Override
        public void onComplete(Bundle values) {

            String token = facebook.getAccessToken();
            long token_expires = facebook.getAccessExpires();
            Log.d(TAG, "AccessToken: " + token);
            Log.d(TAG, "AccessExpires: " + token_expires);
            sharedPrefs = PreferenceManager
                    .getDefaultSharedPreferences(context);
            sharedPrefs.edit().putLong("access_expires", token_expires).clear()
                    .commit();
            sharedPrefs.edit().putString("access_token", token).clear().commit();
            mAsyncRunner.request("me", new IDRequestListener());
            Toast.makeText(context, "You are logged in", Toast.LENGTH_SHORT).show();

            return;
        }

        @Override
        public void onCancel() {
            Log.d(TAG, "OnCancel");
        }

        @Override
        public void onFacebookError(FacebookError e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onError(DialogError e) {
            // TODO Auto-generated method stub

        }
    }

    private class SessionListener implements AuthListener, LogoutListener {

        public void onAuthSucceed() {
            SessionStore.save(facebook, context);
        }

        public void onAuthFail(String error) {
        }

        public void onLogoutBegin() {
        }

        public void onLogoutFinish() {
            SessionStore.clear(context);
        }
    }

    public Facebook getFacebook() {
        return this.facebook;
    }


}

Can anybody please help 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-25T10:28:08+00:00Added an answer on May 25, 2026 at 10:28 am

    Finally am able to solve my problem myself.

    private static final String[] PERMS = new String[] { "publish_stream" };
    ----->
    
    
    this.facebookConnector = new FacebookConnect(APP_ID, this, getApplicationContext(), PERMS);
    
    ---->
    
    JSONObject json = Util.parseJson(response);
    
    
    fbGender = json.getString("gender");
    
    
    fbName = json.getString("name");
    

    This is a piece of my code how i extracted the data

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

Sidebar

Related Questions

I have little question about how web browser retrieve webpage? I know this User
I'm making this method retrieve records from the Data Base. As you can see
Using this file as source, I have a situation where I need to retrieve
How can I retrieve the current working directory of cmd.exe? This seems possible. For
I'm trying to retrieve a variable from an extended class. This is how my
Hi (sorry for my ugly english) I wonder if this is possible to retrieve
Let's say I have this url: www.example.com/test.php?page=4 How do i retrieve the value of
The stored procedure builds without any problem. The purpose of this is to take
I would like to programmatically retrieve the query text of every query stored in
I've been able to finally get python-openid to authenticate a user, but I'm not

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.