2013-10-28 61 views
7

ERROR:CursorWrapperInner(10908):沒有事先關閉()Facebook的Android的碎片登錄

我一直試圖讓Facebook的代碼與我的應用程序工作完成光標。由於某些原因,即使樣本也會出現這個錯誤?我不知道爲什麼,但這裏是我的片段,我得到了上述同樣的錯誤。

代碼:

package com.fragments; 

public class MainDisplayFragment extends Fragment { 

    private static final String TAG = "MainFragment"; 
    private UiLifecycleHelper uiHelper; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     View view = inflater.inflate(R.layout.main_display_fragment, container, 
       false); 

     uiHelper = new UiLifecycleHelper(this.getActivity(), callback); 
     uiHelper.onCreate(savedInstanceState); 

     // Facebook login button. 
     LoginButton authButton = (LoginButton) view 
       .findViewById(R.id.authButton); 
     authButton.setFragment(this); 
     // Set Application ID. 
     authButton.setReadPermissions(Arrays.asList("user_friends", 
       "user_about_me", "user_birthday", "user_likes", "user_status")); 

     return view; 
    } 

    private void onSessionStateChange(Session session, SessionState state, 
      Exception exception) { 
     if (state.isOpened()) { 
      Log.i(TAG, "Logged in..."); 
     } else if (state.isClosed()) { 
      Log.i(TAG, "Logged out..."); 
     } 
    } 

    private Session.StatusCallback callback = new Session.StatusCallback() { 
     @Override 
     public void call(Session session, SessionState state, 
       Exception exception) { 
      onSessionStateChange(session, state, exception); 
     } 
    }; 

    @Override 
    public void onResume() { 
     super.onResume(); 
     uiHelper.onResume(); 
    } 

    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     uiHelper.onActivityResult(requestCode, resultCode, data); 

    } 

    @Override 
    public void onPause() { 
     super.onPause(); 
     uiHelper.onPause(); 
    } 

    @Override 
    public void onDestroy() { 
     super.onDestroy(); 
     uiHelper.onDestroy(); 
    } 

    @Override 
    public void onSaveInstanceState(Bundle outState) { 
     super.onSaveInstanceState(outState); 
     uiHelper.onSaveInstanceState(outState); 
    } 
} 
+0

你試過內活動代碼?這個是來做什麼的? 'authButton.setFragment(this);'你是否嘗試過用於檢索用戶狀態的共享首選項?有沒有可能'callback'爲它們中的任何一個返回空值? –

+0

我已經有一段時間在你的評論之前修復了,我很抱歉沒有更快發佈。看下面的所有類似的問題。 – thekevshow

回答

0

回答我的問題來自於移動交互的活動。這樣我們就可以監視我們主要活動中的會話狀態。不幸的是,根據文件,它不應該是必要的,但這是我用於那些持續存在的問題的修復。

CODE:

// session callback status 
    private Session.StatusCallback callback = new Session.StatusCallback() { 
     @Override 
     public void call(Session session, SessionState state, 
       Exception exception) { 

      onSessionStateChange(session, state, exception); 
     } 
    }; 

    // on click listener for the login button 
    public OnClickListener loginButtonListener = new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 

      // call the handler 
      onLoginButtonClick(); 

     } 
    }; 

    // session callback 
    public void onLoginButtonClick() { 

     Session session = Session.getActiveSession(); 
     if (!session.isOpened() && !session.isClosed()) { 
      session.openForRead(new Session.OpenRequest(this) 
        .setCallback(callback)); 
     } else { 
      Session.openActiveSession(this, true, callback); 
     } 

    } 

    public void intializeSession(Bundle savedInstanceState) { 

     // initialize the facebook session 
     Session session = Session.getActiveSession(); 
     if (session == null) { 
      if (savedInstanceState != null) { 
       session = Session.restoreSession(this, null, callback, 
         savedInstanceState); 
      } 
      if (session == null) { 
       session = new Session(this); 
      } 
      Session.setActiveSession(session); 
      if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) { 
       session.openForRead(new Session.OpenRequest(this) 
         .setCallback(callback)); 
      } 
     } 

    } 

    private void onSessionStateChange(Session session, SessionState state, 
      Exception exception) { 

     // IF the session is opened 
     if (session.isOpened()) { 

      //TODO YOUR INTERACTIONS HERE WHEN OPEN 

     } 
     // else IF there session is closed 
     else if (session.isClosed()) { 

      // TODO YOUR INTERACTIONS HERE WHEN CLOSED 

     } 
    }