android - login to app using facebook not working -


i've started app has facebook login. integrated facebook sdk , done following things.

activity.java

public class startactivity extends fragmentactivity { private callbackmanager callbackmanager;   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     facebooksdk.sdkinitialize(getapplicationcontext());     callbackmanager = callbackmanager.factory.create();     if (build.version.sdk_int >= build.version_codes.lollipop) {         window window = this.getwindow();         window.addflags(windowmanager.layoutparams.flag_draws_system_bar_backgrounds);         window.clearflags(windowmanager.layoutparams.flag_translucent_status);      }     setcontentview(r.layout.activity_start);      if (savedinstancestate == null) {         getsupportfragmentmanager()                 .begintransaction()                 .add(r.id.fragment_container, new loginfragment())                 .commit();     }  } } 

loginfragment.java

public class loginfragment extends fragment implements view.onclicklistener { private edittext et_username, et_password; private button btn_login, btn_register, btn_fb; private loginbutton loginbutton; private callbackmanager callbackmanager; view rootview; context mcontext;   @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     facebooksdk.sdkinitialize(getactivity());     callbackmanager = callbackmanager.factory.create(); }  @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {     view rootview = inflater.inflate(r.layout.login_fragment, container, false);     et_username = (edittext) rootview.findviewbyid(r.id.username);     et_password = (edittext) rootview.findviewbyid(r.id.password);     btn_login = (button) rootview.findviewbyid(r.id.loginbutton);     btn_register = (button) rootview.findviewbyid(r.id.registerbutton);     loginbutton = (loginbutton) rootview.findviewbyid(r.id.login_button);     btn_login.setonclicklistener(this);     btn_register.setonclicklistener(this);     mcontext = getactivity();     loginbutton.registercallback(callbackmanager, new facebookcallback<loginresult>() {         @override         public void onsuccess(loginresult loginresult) {             toast.maketext(mcontext, "user id: " + loginresult.getaccesstoken().getuserid() + "\n" + "auth token: "                     + loginresult.getaccesstoken().gettoken(), toast.length_short).show();         }          @override         public void oncancel() {             toast.maketext(mcontext, "attempt cancelled", toast.length_short).show();         }          @override         public void onerror(facebookexception e) {             toast.maketext(mcontext, "attempt failed", toast.length_short).show();         }     });     return rootview; }  @override public void onclick(view v) {     switch (v.getid()) {         case r.id.loginbutton:             toast.maketext(getactivity(), "login", toast.length_short).show();             break;         case r.id.registerbutton:             toast.maketext(getactivity(), "register", toast.length_short).show();             break;     } }  @override public void onactivityresult(int requestcode, int resultcode, intent data) {     callbackmanager.onactivityresult(requestcode, resultcode, data); }  @override public void onresume() {     super.onresume(); }  @override public void onpause() {     super.onpause(); } 

}

when click loginbutton, facebook login page opened , ask authorization, after press ok nothing happens go fragment page. exact thing worked(userid , accesstoken toast , changing loginbutton logout) when used activity. used same logic in fragment. went wrong??help

in activity contains fragment, this

@override protected void onactivityresult(int requestcode, int resultcode, intent data) {         fragment.onactivityresult(requestcode, resultcode, data); } 

if don't have reference fragment, can using

getsupportfragmentmanager().findfragmentbyid(<container-res-id>); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -