title: FB SDK (4.5.1) login : Connection Failed
body: <p>I'm using FB SDK version 4.5.1 with eclipse to login to Facebook. Sometimes it login successfully, but some other times it gives me this error message " CONNECTION FAILURE". Is this a problem with my Internet connection or code?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      FacebookSdk.sdkInitialize(getApplicationContext());
      Log.d(TAG,"Fb initialzed");
      callbackManager = CallbackManager.Factory.create();
  
      //LoginButton loginButton= (LoginButton)findViewById(R.id.fb_login_button);
  
  
   LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback&lt;LoginResult&gt;() {
  
          @Override
          public void onSuccess(LoginResult result) {
              // TODO Auto-generated method stub
  
  
              Log.d(TAG,"Login success");
              Intent I = new Intent(getApplicationContext(), Games.class);
              startActivity(I);
          }
  
             private void showAlert() {
                 new AlertDialog.Builder(GameSurvey.this)
                         .setTitle(R.string.cancelled)
                         .setMessage(R.string.permission_not_granted)
                         .setPositiveButton(R.string.ok, null)
                         .show();
             }
          @Override
          public void onCancel() {
              // TODO Auto-generated method stub
              Log.d(TAG,"Login cancelled");
          }
  
          @Override
          public void onError(FacebookException error) {
              // TODO Auto-generated method stub
              if(error instanceof FacebookAuthorizationException)
                  Log.d(TAG,error.toString());
                  showAlert();
  
          }
      });
      Log.d(TAG, "here");
  
  
      setContentView(R.layout.activity_game_survey);
  
      profileTracker = new ProfileTracker() {
          @Override
          protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
              updateUI();
              // It's possible that we were waiting for Profile to be populated in order to
              // post a status update.
  
          }
      };
      profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);
  
  
  
  
  
  }
  </code></pre>