2

我通过 facebook 开发者网站https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/关注 android 登录

本教程(使用 facebook 登录创建新的 android 项目)第 6 步。一切正常。但它是第一次加载时登录。

我希望它在单击按钮时登录,成功后它会进入另一个活动。

这是来自 facebook 开发者的教程

    package com.firstandroidapp;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.TextView;
import com.facebook.*;
import com.facebook.model.*;

public class MainActivity extends Activity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // start Facebook Login
    Session.openActiveSession(this, true, new Session.StatusCallback() {

      // callback when session changes state
      @Override
      public void call(Session session, SessionState state, Exception exception) {
        if (session.isOpened()) {

          // make request to the /me API
          Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

            // callback after Graph API response with user object
            @Override
            public void onCompleted(GraphUser user, Response response) {
              if (user != null) {
                TextView welcome = (TextView) findViewById(R.id.welcome);
                welcome.setText("Hello " + user.getName() + "!");
              }
            }
          });
        }
      }
    });
  }

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
  }

}
4

1 回答 1

3

您需要从 onCompleted 中开始您的下一个 Activity。

基本上:

Intent intent = new Intent(MainActivity.this,nextActivity.class);
startActivity(intent);
于 2012-12-17T06:01:37.043 回答