1
這裏是我的代碼:Android Facebook sdk,sharedPreferences永遠不會改變?
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
,並在註銷功能,我想註銷表單Facebook和清除sharedPreferences還有: 公共無效註銷(查看視圖){
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) {}
});
}
所以,這裏是一個問題:不管我多麼努力,存儲在sharedPreferences中的值都沒有改變。我嘗試清除(),刪除(),提交(),應用()等..... 請幫助!
謝謝你提醒我 – crystalWing
請人幫幫我!! – crystalWing