1
After loginfacebook(Fragment) I would like to change from Activity, for example to register, as I do?
public class Loginfacebook extends Fragment {
private LoginButton loginButton;
private CallbackManager callbackManager;
private AccessTokenTracker accessTokenTracker;
private AccessToken accessToken;
private Fragment1 fragment1;
@Override
public View onCreateView(
final LayoutInflater inflater,
final ViewGroup container,
Bundle savedInstanceState) {
FacebookSdk.sdkInitialize(getContext());
callbackManager = CallbackManager.Factory.create();
final View view = inflater.inflate(R.layout.loginfacebook, container, false);
//
loginButton = (LoginButton)view.findViewById(R.id.loginfacebook);
loginButton.setFragment(this);
loginButton.setReadPermissions(Arrays.asList("email"));
loginButton.setReadPermissions(Arrays.asList("public_profile"));
// Callback registration
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AlertDialog.Builder dlg = new AlertDialog.Builder(getContext());
dlg.setMessage("deu"+loginResult.getAccessToken().getUserId());
dlg.setNeutralButton("ok",null);
dlg.show();
}
@Override
public void onCancel() {
AlertDialog.Builder dlg = new AlertDialog.Builder(getContext());
dlg.setMessage("cancelou");
dlg.setNeutralButton("ok",null);
dlg.show();
}
@Override
public void onError(FacebookException exception) {
AlertDialog.Builder dlg = new AlertDialog.Builder(getContext());
dlg.setMessage("deu erro");
dlg.setNeutralButton("ok",null);
dlg.show();
}
});
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(
AccessToken oldAccessToken,
AccessToken currentAccessToken) {
// Set the access token using
// currentAccessToken when it's loaded or set.
}
};
return view;
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
if(isLoggedIn()){
Intent intent = new Intent(getContext(), Cadastro.class);
startActivity(intent);
}
public boolean isLoggedIn() {
AccessToken accessToken = AccessToken.getCurrentAccessToken();
return accessToken != null;
}
}
I don’t understand very well. You want after logging in via facebook, go to another
Activity
?– viana