Android - Facebook login causes onResume error onl

2019-04-07 18:42发布

问题:

I can successfully connect to facebook and get friendlist. All connections are OK. But when I delete data of Facebook(through settings->Applications) and my app's, a login problem occurs. [SDK 3.5]

  1. Launch my app
  2. Make a facebook connection
  3. Facebook asks for username and Password, enter them
  4. Wait a little
  5. It shows Permission screen that asks for basic user info and error occurs:" Your application stop working unexpectedly. Please try again (FORCE CLOSE)"

When I click Force Close, same error occurs again and again suddenly(while permission screen is still behind). If I can be quick enough, I click Force Close and then Allow Permission, everything goes OK and I can see my friends. So this FORCE CLOSE error means something like nothing? In the log, there are 3-4 of same Fatal Exception messages because each time I click FORCE CLOSE, the error occurs again. This error occurs when I try application on my phone(SE Xperia Arc S, 2.3.3). But when I try on Emulators, the error doesn't occur. It works without problem. (emulators are 2.3.3 and 4.2)

    09-04 18:09:47.916 E/AndroidRuntime(29511): FATAL EXCEPTION: main
09-04 18:09:47.916 E/AndroidRuntime(29511): java.lang.RuntimeException: Unable to resume activity {com.ilanharitasi/com.facebook.LoginActivity}: java.lang.NullPointerException
09-04 18:09:47.916 E/AndroidRuntime(29511): Caused by: java.lang.NullPointerException
09-04 18:09:47.916 E/AndroidRuntime(29511):     ... 12 more
09-04 18:09:51.526 E/AndroidRuntime(29538): FATAL EXCEPTION: main
09-04 18:09:51.526 E/AndroidRuntime(29538): java.lang.RuntimeException: Unable to resume activity {com.ilanharitasi/com.facebook.LoginActivity}: java.lang.NullPointerException
09-04 18:09:51.526 E/AndroidRuntime(29538): Caused by: java.lang.NullPointerException
09-04 18:09:51.526 E/AndroidRuntime(29538):     ... 12 more
09-04 18:09:53.786 E/AndroidRuntime(29547): FATAL EXCEPTION: main
09-04 18:09:53.786 E/AndroidRuntime(29547): java.lang.RuntimeException: Unable to resume activity {com.ilanharitasi/com.facebook.LoginActivity}: java.lang.NullPointerException
09-04 18:09:53.786 E/AndroidRuntime(29547): Caused by: java.lang.NullPointerException
09-04 18:09:53.786 E/AndroidRuntime(29547):     ... 12 more
09-04 18:09:55.516 E/AndroidRuntime(29557): FATAL EXCEPTION: main
09-04 18:09:55.516 E/AndroidRuntime(29557): java.lang.RuntimeException: Unable to resume activity {com.ilanharitasi/com.facebook.LoginActivity}: java.lang.NullPointerException
09-04 18:09:55.516 E/AndroidRuntime(29557): Caused by: java.lang.NullPointerException
09-04 18:09:55.516 E/AndroidRuntime(29557):     ... 12 more
09-04 18:09:57.776 E/AndroidRuntime(29564): FATAL EXCEPTION: main
09-04 18:09:57.776 E/AndroidRuntime(29564): java.lang.RuntimeException: Unable to resume activity {com.ilanharitasi/com.facebook.LoginActivity}: java.lang.NullPointerException
09-04 18:09:57.776 E/AndroidRuntime(29564): Caused by: java.lang.NullPointerException
09-04 18:09:57.776 E/AndroidRuntime(29564):     ... 12 more
09-04 18:09:59.186 E/dalvikvm(29571): Could not find class 'dalvik.system.BaseDexClassLoader', referenced from method com.facebook.common.dextricks.SystemClassLoaderAdder.a
09-04 18:09:59.586 E/dalvik-internals(29571): Failed to look up ladDumpProfiles
09-04 18:09:59.586 E/dalvik-internals(29571): Failed to look up ladResetProfiles
09-04 18:09:59.586 E/dalvik-internals(29571): Failed to look up ladPrintHeaderInfo
09-04 18:09:59.936 E/AndroidRuntime(29578): FATAL EXCEPTION: main
09-04 18:09:59.936 E/AndroidRuntime(29578): java.lang.RuntimeException: Unable to resume activity {com.ilanharitasi/com.facebook.LoginActivity}: java.lang.NullPointerException
09-04 18:09:59.936 E/AndroidRuntime(29578): Caused by: java.lang.NullPointerException
09-04 18:09:59.936 E/AndroidRuntime(29578):     ... 12 more
09-04 18:10:02.006 E/AndroidRuntime(29585): FATAL EXCEPTION: main
09-04 18:10:02.006 E/AndroidRuntime(29585): java.lang.RuntimeException: Unable to resume activity {com.ilanharitasi/com.facebook.LoginActivity}: java.lang.NullPointerException
09-04 18:10:02.006 E/AndroidRuntime(29585): Caused by: java.lang.NullPointerException
09-04 18:10:02.006 E/AndroidRuntime(29585):     ... 12 more
09-04 18:10:04.566 E/ONRESUME(29605): Onresume worked
09-04 18:10:04.636 E/STATEM  (29605): OPENING
09-04 18:10:05.186 E/ONRESUME(29605): Onresume worked

After the first connection, I can find my friends without any error. It only happens just after I connect Facebook for the first time and it asks my username and password(and then clicking Login)

@Override
  public void onCreate(Bundle savedInstanceState) {

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

    setContentView(R.layout.activity_fb_findfriends);
    LinearLayout v = (LinearLayout) findViewById(R.id.fb_app_users);
    openSession(v);

  }

public void openSession(View v){
        // start Facebook Login
        Session.openActiveSession(this, true, callback);

    }

@Override
  protected void onResume() {
      super.onResume();
      uiHelper.onResume();
      Log.e("ONRESUME", "Onresume çalıştı");
  }

private void requestMyAppFacebookFriends(Session session) {
        Request friendsRequest = createRequest(session);
        friendsRequest.setCallback(new Request.Callback() {

            @Override
            public void onCompleted(Response response) {

                List<GraphUser> friends = getResults(response);
                //Display Friends
            }
        });
    friendsRequest.executeAsync();
}

Also I couldn't understand what is null from the log output.

UPDATE! I found the line where error occurs. It is inside the com.facebook.AuthorizationClient.java line 135

void startOrContinueAuth(AuthorizationRequest request) {
        if (appEventsLogger == null || appEventsLogger.getApplicationId() != request.getApplicationId()) {
            Log.e("HATA!", "BOOM");
            appEventsLogger = AppEventsLogger.newLogger(context, request.getApplicationId());
        }

And this startOrContinueAuth method is fired in com.Facebook.LoginActivity

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

    // If the calling package is null, this generally means that the callee was started
    // with a launchMode of singleInstance. Unfortunately, Android does not allow a result
    // to be set when the callee is a singleInstance, so we log an error and return.
    if (callingPackage == null) {
        Log.e(TAG, "Aheyy"+NULL_CALLING_PKG_ERROR_MSG);
        finish();
        return;
    }

    authorizationClient.startOrContinueAuth(request);
}
        if (getInProgress()) {
            continueAuth();
        } else {
            authorize(request);
        }
    }

UPDATE 2!

  • I got very confused. I simplified my application to the very basic openActiveSession() method. Crashes
  • I tried sample application of Facebook, FriendPicker and it also crash with the same log error output.
  • tried on emulator, it works but when I rotate the screen when authorization screen shows up(cancel-allow), same error occurs(unable to onResume blah blah...) Getting the same error on Facebook's sample application is weird

回答1:

I don't believe that this is an issue with your app. People have been reporting this bug and I just answered a similar question here. Basically Facebook released a new version of their SDK yesterday fixing the onResume NPE crash in their AuthorizationClient. See if upgrading fixes your issue.



回答2:

According to the change log https://developers.facebook.com/docs/android/change-log-3.x/,
in facebook version 3.5.1 fixed a lot of problems about the authentication and app events logging,so maybe it has been solved in newest one version which can be download from https://github.com/facebook/facebook-android-sdk. I hope it can solve your problem:)



回答3:

Basically this problem occurs when the calling activity is not live or destroyed. In android the method onActivityResult() is called after login. The Activity is destroyed forcefully by the mobile( Don't keep activities option enables in the developers options settings). Please Once cross check in the developers options setting that the Don't keep activities is enabled or disabled.



回答4:

Make sure in your manifest that the lgin activity is in portrait. There is an issue with losing the activity if it isn't in portrait..which is very lame...:|