简体   繁体   English

在Android App中后台运行AsyncTask(Facebook登录)时切换活动

[英]Switching Activity when AsyncTask (Facebook login) is running in the background in Android App

So, on a button click, the Facebook login dialog pops up. 因此,单击按钮,将弹出Facebook登录对话框。 After the user logs in, I want to then go to the another activity. 用户登录后,我想再转到另一个活动。 The problem is, when I do the Facebook work and then start a new activity, the activity starts before the login process is complete. 问题是,当我完成Facebook工作并开始新活动时,该活动在登录过程完成之前就开始了。 Any ideas on how I can get the new activity to start only when the login process is complete? 关于如何才能仅在登录过程完成后才能启动新活动的任何想法? Thanks. 谢谢。

login.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Session s = new Session(MainActivity.this);
        Session.setActiveSession(s);
        Session.OpenRequest request = new Session.OpenRequest(
                MainActivity.this);
        request.setPermissions(Arrays.asList("public_profile", "email"));
        request.setCallback(new Session.StatusCallback() {
            // callback when session changes state
            @Override
            public void call(Session session, SessionState state,
                    Exception exception) {
                if (session.isOpened()) {
                        Request.newMeRequest(session,
                            new Request.GraphUserCallback() {
                                    @Override
                                    public void onCompleted(GraphUser user,
                                        Response response) {
                                    if (user != null) {

                                        userName = user.getName();
                                        userEmail = (String) user
                                                .getProperty("email");
                                        userID = user.getId();

                                    } else {
                                        Toast.makeText(
                                                getApplicationContext(),
                                                "Error User Null",
                                                Toast.LENGTH_SHORT)
                                                .show();                                                }
                                }
                            }).executeAsync();
                }
            }
        }); // end of call;
        s.openForRead(request);

        startActivity(new Intent(MainActivity.this, NextActivity.class));

    }
});

move the call 移动电话

startActivity(new Intent(MainActivity.this, NextActivity.class));

in onCompleted in the if (user != null) block. if (user != null)块中的onCompleted中。 At this point the MeRequest is completed and a user was successfully returned. 至此, MeRequest已完成,并且已成功返回用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM