java - onSessionStateChange does whatever it wants -
i know title may odd, since i've changed app's lifecycle moving login cycle mainactivity
loginactivity
, facebook's onsessionstatechange
absolutely nothing of ask him.
the login's lifecycle, using facebook, logs user facebook, gets uid fb, , retrieve infos our app's server using uid, , starts next activity. i've changed app's lifecycle, starts next activity without getting uid.
so here code onsessionstatechange
in loginactivity
:
private void onsessionstatechange(session session, sessionstate sessionstate, exception exception){ //make change if activity visible if(isresumed){ log.i("facebook", "fb state changed"); fragmentmanager fragmentmanager = getsupportfragmentmanager(); //clear stack for(int = 0; < fragmentmanager.getbackstackentrycount(); i++){ fragmentmanager.popbackstack(); } if(sessionstate.isopened()){ log.i("facebook", "fb session opened"); //if facebook session opened, display default behavior , add uid //to shared preferences //now let's update shared preferences uid. final session requestsession = session; request request = request.newmerequest(session, new request.graphusercallback(){ @override public void oncompleted(graphuser user, response response){ if(requestsession == session.getactivesession() && user != null){ log.i("facebook", "request uid " + user.getid()); getuserbyuidtask usertask = new getuserbyuidtask(getparent()); usertask.execute(new user(user.getid())); //get , update current user database try{ mainactivity.scurrentuser = usertask.get(); log.i("facebook", mainactivity.scurrentuser.firstname + "'s uid " + mainactivity.scurrentuser.uid); updatecurrentusersettings(); }catch (interruptedexception e){ //todo: handle , display error log.e("facebook", "error getting user uid"); return; }catch (executionexception e){ //todo: handle , display error log.e("facebook", "error getting user uid"); return; } log.d("facebook", "displaying main activity"); //startactivity(new intent(getparent(), mainactivity.class)); }else{ log.e("facebook", "error when making newmerequest"); } } }); request.executeasync(); }else if(sessionstate.isclosed()){ log.i("myapp", "closing session"); //remove current uid prevent unauthorized authentication , gcm bind getsharedpreferences(userprefsfile,0).edit().clear().commit();; try { googlecloudmessaging.getinstance(this).unregister(); } catch (ioexception e) { //todo: handle e.printstacktrace(); } } } }
as can see, should lot of log
output, telling me session being opened, , mainactivity
should not started (since commented testing purposes). absolutely no log output, , mainactivity
still gets launched, though i've commented it. , when activity started, current user not updated or created, leading classic crash.
also may need other loginactivity
's facebook related methods :
private boolean isresumed = false; private uilifecyclehelper uihelper; private session.statuscallback sessionstatuscallback = new session.statuscallback(){ @override public void call(session session, sessionstate state, exception exception){ onsessionstatechange(session, state, exception); } }; @override public void oncreate(bundle savedinstancestate){ super.oncreate(savedinstancestate); //bind fb session callback listener ui helper , call lifecycle method uihelper = new uilifecyclehelper(this, sessionstatuscallback); uihelper.oncreate(savedinstancestate); setcontentview(r.layout.activity_login); registerchoicesfragment registerfragment = new registerchoicesfragment(); getsupportfragmentmanager().begintransaction().replace(r.id.login_container, registerfragment).commit(); }//end oncreate @override public void onresume(){ super.onresume(); uihelper.onresume(); isresumed = true; } @override public void onpause(){ super.onpause(); uihelper.onpause(); isresumed = false; } @override public void onactivityresult(int requestcode, int resultcode, intent data){ super.onactivityresult(requestcode, resultcode, data); uihelper.onactivityresult(requestcode, resultcode, data); } @override public void ondestroy(){ super.ondestroy(); uihelper.ondestroy(); } @override public void onsaveinstancestate(bundle outstate){ super.onsaveinstancestate(outstate); uihelper.onsaveinstancestate(outstate); } @override protected void onresumefragments(){ super.onresumefragments(); session session = session.getactivesession(); if(session != null && session.isopened()){ //if current facebook session exists , opened, make sure autheticated //ui selected startactivity(new intent(this, lovrmain.class)); } }
so here is, have absolutely no idea of makes facebook api behave it wants, , i've come point realize hate coding facebook as hate coding ie.
Comments
Post a Comment