我有一個片段,我想存儲Facebook的共享偏好。我無法在獲取首選項功能中編寫私有模式。而且我想在另一個片段中訪問這個共享偏好。我該怎麼做?如何在Android上的片段中使用共享首選項?
這裏是我的代碼...
Session.openActiveSession(getActivity(), true, new Session.StatusCallback()
{
@Override
public void call(Session session,
SessionState state,
Exception exception) {
if (session.isOpened()) {
Request.executeMeRequestAsync(session,new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
t = (TextView)rootView.findViewById(R.id.textView2);
p = (ProfilePictureView)rootView.findViewById(R.id.profilePictureView1);
p.setProfileId(user.getId());
s = user.getName();
t.setText(s);
s1 = user.getId();
private void SavePreferences(String key,String value)
{
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(key, value);
editor.commit();
}
嘗試'Context.MODE_PRIVATE'代替。 –
使用preferencemanager.getsharedpreference(上下文)... – Ranjit
更正您的代碼的格式 - (提示:沒有水平滾動條等) –