I'm sure it was a JNI problem. The following combination made my code working:
- Moving OnLoginListener one level up
- Adding runOnUiThread
- Adding try/catch block
- Checking mSimpleFacebook != null and fixing IsLoggedIn function in order not to call for Login if already logged in (well, I see that this situation is handled in library, but Facebook really tried to make a duplicate login).
So, my final code is:
private static OnLoginListener mOnLoginListener = new OnLoginListener() {
// the same code as in question above
};
public static void login(final Activity activity) {
activity.runOnUiThread(new Runnable() {
public void run() {
if (mSimpleFacebook == null)
mSimpleFacebook = SimpleFacebook.getInstance(activity);
try {
mSimpleFacebook.login(mOnLoginListener);
} catch (Exception ex) {
Log.e(TAG, "Login error: ", ex);
}
}
});
}