0
我試圖在我的Android應用程序的SharedPreferences中保存Facebook ID和Facebook的usrname使用它隨時隨地我想要,但logcat返回我「空」 這裏是我的「Oncomplete」 Facebook的方法:保存JSON Facebook的結果在SharedPref
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
String result = response.toString();
SharedPreferences pref = getActivity().getPreferences(0);
SharedPreferences.Editor edt = pref.edit();
edt.putString("result", result);
edt.commit();
Log.i("string","PROVAAAAAA");
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link");
request.setParameters(parameters);
request.executeAsync();
}
我注意到,logcat的不寫道:「PROVAAAAAAA」 這裏是我的回調方法:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
CallbackManager callbackManager = CallbackManager.Factory.create();
callbackManager.onActivityResult(requestCode, resultCode, data);
SharedPreferences pref = getActivity().getPreferences(0);
SharedPreferences.Editor edt = pref.edit();
String id = pref.getString("facebook_id", "empty");
Log.i("RESULT", id);
Log.i("RESULT", "***************");
edt.commit();
}
那我該怎麼辦? @roarster –
@Jack_usti我已經添加了一些代碼給我的答案 – roarster