After the loginfacebook (fragment) I would like to change the activity, for example to register, how do I?
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;
}
}