I am using Facebook Android SDK to allow SSO. I have followed the guide and the tutorial in Hackbook but it happens that the phone seems stucked on a white screen, after 10 seconds a progress dialog appears and the process continues as expected.
I have tried hard to fix the issue (async tasks, transparent layouts) but it seems nothing is working.
This is the code in facebook activity:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.facebook_activity);
/*
* Get existing access_token if any
*/
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if (access_token != null) {
facebook.setAccessToken(access_token);
}
if (expires != 0) {
facebook.setAccessExpires(expires);
}
/*
* Only call authorize if the access_token has expired.
*/
// showProgress();
if (!facebook.isSessionValid()) {
authorizeFacebook();
} else {
signalResult();
}
}
private void authorizeFacebook() {
facebook.authorize(this, new String[] { "email", "offline_access",
"publish_stream", "user_about_me" }, new DialogListener() {
@Override
public void onComplete(Bundle values) {
// SharedPreferences.Editor editor = mPrefs.edit();
// editor.putString("access_token",
// facebook.getAccessToken());
// editor.putLong("access_expires",
// facebook.getAccessExpires());
// editor.commit();
signalResult();
// retrieve call obtain information and register
}
@Override
public void onFacebookError(FacebookError error) {
}
@Override
public void onError(DialogError e) {
}
@Override
public void onCancel() {
}
});
}
private void signalResult() {
// retrieve user info
new AsyncFacebookRunner(facebook).request("me",
new AsyncFacebookRunner.RequestListener() {
@Override
public void onMalformedURLException(
MalformedURLException e, Object state) {
authorizeFacebook();
}
@Override
public void onIOException(IOException e, Object state) {
authorizeFacebook();
}
@Override
public void onFileNotFoundException(
FileNotFoundException e, Object state) {
authorizeFacebook();
}
@Override
public void onFacebookError(FacebookError e, Object state) {
authorizeFacebook();
}
@Override
public void onComplete(String response, Object state) {
Intent intent = new Intent();
String accessToken = facebook.getAccessToken();
String id = null;
JSONObject json;
try {
json = new JSONObject(response);
id = json.getString("id");
intent.putExtra(WeOrderApplication.FACEBOOK_USER, id);
intent.putExtra(WeOrderApplication.FACEBOOK,
accessToken);
// hideProgress();
setResult(RESULT_OK, intent);
finish();
} catch (JSONException e) {
authorizeFacebook();
e.printStackTrace();
}
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
and it is called through a simple StartActivity. facebook_activity is a linearLayout without anything in it. I have set a translucent theme (android:theme="@android:style/Theme.Translucent.NoTitleBar") to FacebookActivity to make it at least transparent but it didn't work either.
Thanks to anyone that could help fixing this.