0

は現在、これは私のFBログインがどのように見えるかです:Facebook SDKでSharedPreferencesを使用するにはどうすればよいですか?

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_login); 
    TAG = "Login.Activity"; 

    //Callback manager manages callbacks into the FB SDK from an Activity's onActivityResult() Method. 
    callbackManager = CallbackManager.Factory.create(); 
    loginButton = (LoginButton) findViewById(R.id.login_button); 
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { 
     //If login in successful, 
     @Override 
     public void onSuccess(LoginResult loginResult) { 
      Profile profile = Profile.getCurrentProfile(); 
      goMainScreen(profile); 
     } 
     @Override 
     public void onCancel() { 
      Toast.makeText(getApplicationContext(),R.string.cancel_login, Toast.LENGTH_LONG).show(); 
     } 

     @Override 
     public void onError(FacebookException error) { 
      Toast.makeText(getApplicationContext(), R.string.error_login, Toast.LENGTH_LONG).show(); 
     } 
    }); 
} 
private void goMainScreen(Profile profile) { 
    if(profile != null){ 
     //Passing in the name,id and photo from the profile. 
     Intent intent = new Intent(this, MainActivity.class); 
     // intent.putExtra("name",profile.getName()); 
     intent.putExtra("id",profile.getId()); 
     intent.putExtra("photo",profile.getProfilePictureUri(200,200)); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); 
     startActivity(intent); 
    } 
} 

@Override 
//All Request Code, Result Code, and data are recieved by the activity 
protected void onActivityResult(int requestCode, int resultCode, Intent data){ 
    super.onActivityResult(requestCode,resultCode,data); 
    callbackManager.onActivityResult(requestCode,resultCode,data); 
} 
} 
私は他の活動を通じて、ユーザー・セッションを追跡し、彼らは私がこれのためにsharedpreferencesを使用before.Wouldにログインしているかどうかを知りたい

?もしそうなら、私はloginActivityの始めにこれをやっていますか?

答えて

0

さてあなたは、SDKを提供したものを使用し、このような方法で作成することができます。

public boolean isLoggedIn() { 
    AccessToken accessToken = AccessToken.getCurrentAccessToken(); 
    return accessToken != null; 
} 
+0

をだから、これはすべての活動中のonCreateメソッドになりますか? – AndroidLearner

+0

ユーザーがFacebook経由でログインしているかどうかを確認したいときはいつでもこのメソッドを呼び出します – HelloSadness

+0

次に共有設定を使用する必要はないと思いますか? – AndroidLearner

関連する問題