Calling new activity after facebook login | Android -
i have 2 activities in android application. on first one, ask user login facebook. after user logs in, collect user data such email, name , call new activity passing these parameters it. below facebook authorize method:
public void loginfb(final view v) { facebook.authorize(this, new string[] { "email", "read_stream" }, new dialoglistener() { @override public void oncomplete(bundle values) { this.getlogininfo(v); } private void getlogininfo(view v) { // todo auto-generated method stub logininfo(v); } @override public void onfacebookerror(facebookerror error) {} @override public void onerror(dialogerror e) {} @override public void oncancel() {} }); } below logininfo() method:
public void logininfo(final view v){ masyncrunner.request("me", new requestlistener(){ @override public void oncomplete(string response, object state) { try{ log.d("profile", response.tostring()); jsonobject json = util.parsejson(response); final string fname1 = json.getstring("first_name"); final string lname1 = json.getstring("last_name"); final string email = json.getstring("email"); intent fblogged = new intent(); bundle passdata = new bundle(); passdata.putstring("fname", fname1); passdata.putstring("lname", lname1); passdata.putstring("email", email); fblogged.putextras(passdata); fblogged.setclass(v.getcontext(), requestfb.class); startactivity(fblogged); } catch(jsonexception e){ log.w("this", "eror"); } } @override public void onioexception(ioexception e, object state) { // todo auto-generated method stub } @override public void onfilenotfoundexception(filenotfoundexception e, object state) { // todo auto-generated method stub } @override public void onmalformedurlexception(malformedurlexception e, object state) { // todo auto-generated method stub } @override public void onfacebookerror(facebookerror e, object state) { // todo auto-generated method stub } }); } so, new activity starting on oncomplete() of getting user data.
this works perfectly, when user clicks login, , logs in facebook, first activity page remains on screen few seconds , next activity called. there lag. how can fix lag? when user clicks login , after login authorized, should take user directly second activity. suggestions?
thanks!
it's simple, running fb graph request in new thread (using asyncrunner) when request completed start new activity , that's why "lag".
you should run graph request in new activity instead of first one, like:
public void loginfb(final view v) { facebook.authorize(this, new string[] { "email", "read_stream" }, new dialoglistener() { @override public void oncomplete(bundle values) { intent fblogged = new intent(v.getcontext(), requestfb.class); startactivity(fblogged); } @override public void onfacebookerror(facebookerror error) {} @override public void onerror(dialogerror e) {} @override public void oncancel() {} }); } public class requestfb extend activity { protected void oncreate(bundle savedinstancestate) { facebook facebook = new facebook("your_app_id"); asyncfacebookrunner asyncrunner = new asyncfacebookrunner(facebook); asyncrunner.request("me", new requestlistener(){ try { final jsonobject json = util.parsejson(response); final string fname1 = json.getstring("first_name"); final string lname1 = json.getstring("last_name"); final string email = json.getstring("email"); runonuithread(new runnable() { public void run() { // use data } }); } catch(jsonexception e) { log.w("this", "eror"); } }); } }
Comments
Post a Comment