I stopped programming long ago and well, now that I am developing I am in a mess. What happens is that I have an application with navigation drawer and that calls fragments. Now, I followed a tutorial to login with firebase and I want the logout option to be in a fragment, the settings snippet, but I can not make it work. I have a logout method in mainActivity and I can not call it from the snippet, how could I make it work. Attachment method:
public void logOut(View view){
firebaseAuth.signOut();
Auth.GoogleSignInApi.signOut(googleApiClient).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if(status.isSuccess()){
goLogInScreen();
}else {
Toast.makeText(getApplicationContext(),"No se pudo cerrar sesión",Toast.LENGTH_SHORT).show();
}
}
});
}
and the fragment:
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
btnLogout = (Button) getView().findViewById(R.id.btnLogout);
btnLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MainActivity main = new MainActivity();
main.logOut(v);
}
});
}