I am using the facebook sdk to log the user in.
I call an activity I’ve created that only does the facebook login and should return a result back to the original activity.
Here is how I’m calling this (it’s from the inside of a custom component, that’s why the getContext() is used):
Intent intent = new Intent(getContext(), FacebookAuthenticationActivity.class);
Log.d(TAG, "Starting facebook authentication for result");
((Activity)getContext()).startActivityForResult(intent, REQUEST_FACEBOOK);
And here I want the response:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
Log.d(TAG, "Result from something!");
if(requestCode == LoginWidget.REQUEST_FACEBOOK) {
if(resultCode == RESULT_OK && intent != null) {
Log.d(TAG, "Result from facebook received!");
mLoginWidget.onFacebookLoginSucceeded(intent);
}
}
super.onActivityResult(requestCode, resultCode, intent);
}
On the facebook activity, it’s the code from the facebook developers page. There is no error in that code… For some weird reason the activity calls the onActivityResult before he calls the onCreate on the FacebookAuthActivity.
The coode I’ve written is to log the user in, get some info and finally call:
Intent intent = new Intent();
intent.putExtra("user_json", response);
Log.d(TAG, "Setting result to: " + intent);
setResult(RESULT_OK, intent);
finish();
After reviewing the logs here is what I get:
07-11 16:34:27.992: D/LoginWidget(6863): Starting facebook authentication for result
07-11 16:34:27.992: D/ProgramActivity(6863): I am starting an activity to get a result!
07-11 16:34:28.101: D/ProgramActivity(6863): Result from something!
07-11 16:34:40.875: D/Facebook-authorize(6863): Login Success! access_token=xxx expires=1347195352881
07-11 16:34:40.875: D/FacebookAuthentication(6863): User accepted our app in facebook!
07-11 16:34:42.351: D/FacebookAuthentication(6863): Setting result to: Intent { (has extras) }
So I am out of ideas… For some reason when I call this activity it immediately calls onActivityResult on the parent without the result, then after that, it logs in, sets the real result, calls finish, and never calls onActivityResult with the real response.
Am I missing something here? Do I have to set a specific flag for this activity to correctly return me the result?
It’s just a simple activity with a bunch of async facebook calls and then calls back with the result…
UPDATE
Just to be clearer, I do not get any errors from this code. The problem is that when I set the result, after the login, the originating activity does not receive the result.
The answer is here. This “feature” does not allow activities started using
singleInstaceto call activities for results.I changed my activity to
singleTopand it now works as it should work.