Can't properly sign out of Facebook on Android with Firebase -
i try logging facebook, it's working. when logged out, facebook's "sign out" button still showing in login activity , when clicked on it, can log out. don't wanna that.
but real question is, how sign out of facebook? i'm using both firebase authentication , facebook authentication(with support firebase)
giris.java (log in)
public class giris extends appcompatactivity implements view.onclicklistener { private fancybutton buttonsignin; private edittext edittextemail; private edittext edittextpassword; private textview textviewsignup, textviewsifreunuttum, girismesaji; public boolean cancel = false; public boolean isfirststart; private firebaseauth firebaseauth; private firebaseauth.authstatelistener mauthlistener; private dialog progressdialog; private callbackmanager mcallbackmanager; private static final string tag = "facebooklogin"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_giris); facebooksdk.sdkinitialize(getapplicationcontext()); firebaseauth = firebaseauth.getinstance(); mauthlistener = new firebaseauth.authstatelistener() { @override public void onauthstatechanged(@nonnull firebaseauth firebaseauth) { firebaseuser user = firebaseauth.getcurrentuser(); if (user != null) { // kullanıcı oturumu açtı finish(); startactivity(new intent(getapplicationcontext(), mainactivity.class)); log.d("oncreate", "onauthstatechanged:signed_in:" + user.getuid()); } else { // kullanıcı oturumu kapattı. log.d("oncreate", "onauthstatechanged:signed_out"); } } }; firebaseauth.addauthstatelistener(mauthlistener); mcallbackmanager = callbackmanager.factory.create(); loginbutton loginbutton = (loginbutton) findviewbyid(r.id.login_button); loginbutton.setreadpermissions("email", "public_profile"); loginbutton.registercallback(mcallbackmanager, new facebookcallback<loginresult>() { @override public void onsuccess(loginresult loginresult) { log.d(tag, "facebook:onsuccess:" + loginresult); handlefacebookaccesstoken(loginresult.getaccesstoken()); } @override public void oncancel() { log.d(tag, "facebook:oncancel"); } @override public void onerror(facebookexception error) { log.d(tag, "facebook:onerror", error); } }); @override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); mcallbackmanager.onactivityresult(requestcode, resultcode, data); } private void handlefacebookaccesstoken(accesstoken token) { log.d(tag, "handlefacebookaccesstoken:" + token); authcredential credential = facebookauthprovider.getcredential(token.gettoken()); progressdialog.show(); firebaseauth.signinwithcredential(credential) .addoncompletelistener(this, new oncompletelistener<authresult>() { @override public void oncomplete(@nonnull task<authresult> task) { log.d(tag, "signinwithcredential:oncomplete:" + task.issuccessful()); if(task.issuccessful()) { finish(); intent fgiris=new intent(giris.this, mainactivity.class); fgiris.putextra("giris","facebook"); startactivity(fgiris); } else { log.w(tag, "signinwithcredential", task.getexception()); toast.maketext(giris.this, "facebook ile bağlantı başarız oldu.", toast.length_short).show(); } progressdialog.dismiss(); } }); } else { intent hata = new intent(giris.this, internetcon.class); startactivity(hata); }
mainactivity.java (log out)
public class mainactivity extends appcompatactivity implements navigationview.onnavigationitemselectedlistener{ private fragment fragment; private fragmentmanager fragmentmanager; public textview tarih; final string prefs_name = "myprefsfile"; final string sharedpref_date = "sharedprefdate"; private firebaseauth firebaseauth; private firebaseuser user; private textview textviewuseremail; public circleimageview userimage; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); firebaseauth = firebaseauth.getinstance(); if(firebaseauth.getcurrentuser()==null) { finish(); startactivity(new intent(this,giris.class)); } drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout); final actionbardrawertoggle toggle = new actionbardrawertoggle( this, drawer, toolbar, r.string.navigation_drawer_open, r.string.navigation_drawer_close); drawer.setdrawerlistener(toggle); toggle.syncstate(); navigationview navigationview = (navigationview) findviewbyid(r.id.nav_view); navigationview.setnavigationitemselectedlistener(this); view headerview = navigationview.getheaderview(0); //giriste gelen maili navigation header'a @ textviewuseremail= (textview) headerview.findviewbyid(r.id.textkullanicibilgisi); textviewuseremail.settext(firebaseauth.getcurrentuser().getemail()); userimage= (circleimageview) findviewbyid(r.id.kullanicinavhesapresmi); fragmentmanager = getsupportfragmentmanager(); fragment = new araclarimfragment(); final fragmenttransaction transaction = fragmentmanager.begintransaction(); transaction.add(r.id.main_container, fragment).commit(); @suppresswarnings("statementwithemptybody") @override public boolean onnavigationitemselected(menuitem item) { // navigation itemlerinin click olaylarını burada yapıyoruz. int id = item.getitemid(); if (id == r.id.nav_cikis) { intent gelen=getintent(); string logintype=gelen.getstringextra("giris"); if(logintype=="facebook") { finish(); firebaseauth.signout(); loginmanager.getinstance().logout(); startactivity(new intent(mainactivity.this, giris.class)); } else { finish(); firebaseauth.getinstance().signout(); startactivity(new intent(mainactivity.this, giris.class)); } } drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout); drawer.closedrawer(gravitycompat.start); return true; }
if (id == r.id.nav_cikis) { intent gelen=getintent(); string logintype=gelen.getstringextra("giris"); if(logintype=="facebook") { firebaseauth.getinstance().signout(); loginmanager.getinstance().logout(); startactivity(new intent(mainactivity.this, giris.class)); finish(); } else{ firebaseauth.getinstance().signout(); loginmanager.getinstance().logout(); startactivity(new intent(mainactivity.this, giris.class)); finish();// must last line }
Comments
Post a Comment