I am using this code to allow the user to log in to facebook when the application is opened. Once the user it loged in the application goes to the main menu.
public class facebook_social extends Activity implements LoginListener {
private FBLoginManager fbManager;
Intent intentResult;
Bitmap bmImg = null;
URL myFileUrl =null;
ImageView i;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
intentResult = new Intent(getApplicationContext(), MainMenu.class);
//If the sdk version is Honeycomb the take off strictMode to allow for network connection in main thread.
if(Build.VERSION.SDK_INT >= 11){
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
shareFacebook();
}
public void shareFacebook() {
String permissions[] = { "read_stream", "user_relationship_details",
"user_religion_politics", "user_work_history",
"user_relationships", "user_interests", "user_likes",
"user_location", "user_hometown", "user_education_history",
"user_activities","offline_access"};
fbManager = new FBLoginManager(this,R.layout.black,"173174566087561",permissions);
if (fbManager.existsSavedFacebook()) {
fbManager.loadFacebook();
} else {
fbManager.login();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
fbManager.loginSuccess(data);
}
public void loginFail() {
fbManager.displayToast("Login failed!");
}
public void logoutSuccess() {
fbManager.displayToast("Logout success!");
}
public void loginSuccess(Facebook facebook) {
GraphApi graphApi = new GraphApi(facebook);
User user = new User();
try {
user = graphApi.getMyAccountInfo();
} catch (EasyFacebookError e) {
e.toString();
}
String pkg = getPackageName();
intentResult.putExtra(pkg + ".myName", user.getName());
intentResult.putExtra(pkg + ".myId", user.getId());
startActivity(intentResult);
Intent i = new Intent();
i.putExtra("name", user.getName());
}
}
As you see here the application gives a black backgroud when at this screen to allow the user to log in. What i want to do is, have the log in over top of the main menu. How would i go about doing this?
Integrating it into the main menu activty?
Android is based on stacking Activities, so that’s what you should do. You could use startActivityForResult to handle the login Activity and enable your main Activity when a positive result (=succesful login) is returned.