Reputation: 2669
I'm using the android facebook sdk but I'm running into an issue. I created 2 classes which are:
public class FacebookSession implements Session.StatusCallback {
public interface SessionCallbacks {
public void onSessionOpened(String token, User user, boolean isNewProfile);
public void onSessionOpenFailed(String errorText);
}
public FacebookSession(Activity activity) {
...
}
@Override
public void call(Session session, SessionState sessionState, Exception e) {
switch (sessionState) {
case CLOSED:
...
// Calling SessionCallbacks callbacks here
break;
case CLOSED_LOGIN_FAILED:
...
// Calling SessionCallbacks callbacks here
break;
case OPENED:
...
// Calling SessionCallbacks callbacks here
break;
case OPENED_TOKEN_UPDATED:
...
// Calling SessionCallbacks callbacks here
break;
}
}
}
And in my activity calling facebook session:
public class LoginActivity extends FragmentActivity implements
FacebookSession.SessionCallbacks {
public LoginActivity() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
...
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode,
resultCode, data);
}
@Override
public void onSessionOpened(String token, User user, boolean isNewProfile) {
...
}
}
As you can see I HAVE TO call Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
in the onActivityResult
method of every activity using my FacebookSession
class if I want the result to be returned in the call
callback of FacebookSession
. If I don't, my FacebookSession
just doesn't work. What I want to do here is not having to call this Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
for every activities which use FacebookSession
. Is there a workaround for this? Thank you
Upvotes: 0
Views: 1051
Reputation: 15662
If all of your activities have the potential of either logging the user in, or requesting additional permissions, then no, there's no workaround from implementing the onActivityResult method. Normally, apps that use Facebook login features only do it from a few, limited activities so this is not a problem.
How many activities are you dealing with? If you absolutely think it's an issue, then you can either
Create a BaseActivity class that all of your activities extend, and put the onActivityResult in the parent class; or
Move all of your Facebook integration into a centralized activity.
Upvotes: 2