呼唤新的活动的Facebook登录后|安卓 [英] Calling new activity after facebook login | Android

查看:121
本文介绍了呼唤新的活动的Facebook登录后|安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个活动,我的Andr​​oid应用程序。在第一个,我要求登录facebook的用户。在用户登录时,我收集用户数据,如电子邮件,姓名,并呼吁通过这些参数给它一个新的活动。下面是我的Facebook的授权方式:

I have 2 activities in my android application. On the first one, I ask the user to login with facebook. after the user logs in, i collect the user data such as email, name and call a new activity passing these parameters to it. below is my 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() {}
     });            
    }

下面是我的将LoginInfo()方法:

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

        }           
    });
  }     

所以,我的新的活动开始于的onComplete获取用户数据()

这完美的作品,但是当用户点击登录,并登录与Facebook,第一个活动页面在屏幕上停留几秒钟,然后下一个活动叫。有一个滞后。如何解决滞后?当用户点击登录和之后的登录被授权,它应该采取用户直接在第二活性。有什么建议?

This works perfectly, but when the user clicks login, and logs in with facebook, the first activity page remains on the screen for a few seconds and then the next activity is called. there is a lag. How can I fix the lag? When the user clicks login and after the login is authorized, it should take the user to directly the second activity. Any suggestions?

谢谢!

推荐答案

这很简单,你正在运行在一个新的线程FB图请求(使用的 AsyncRunner 的),但只有当请求完成启动新的活动,这就是为什么你会得到滞后。

It's simple, you are running the fb graph request in a new thread (using the AsyncRunner) but only when that request is completed you start the new activity and that's why you get that "lag".

您应该运行在新的活动,而不是第一个图形的要求,是这样的:

You should run the graph request in the new activity instead of the first one, something 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 the data
                    }
                });
            }
            catch(JSONException e) {
                Log.w("This", "eror");
            }
        });

    }
}

这篇关于呼唤新的活动的Facebook登录后|安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆