简体   繁体   English

Facebook SDK 3.0登录-Facebook进程终止

[英]Facebook SDK 3.0 Login - Facebook process dies

I'm trying to use the Facebook 3.0 SDK's login by following this guide from the facebook developer's: https://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/ 我正在尝试按照来自Facebook开发人员的以下指南使用Facebook 3.0 SDK的登录名: https : //developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/

my problem is that when the user clicks the login button, my activity closes and Facebook's process dies. 我的问题是,当用户单击登录按钮时,我的活动关闭并且Facebook的进程消失了。

this is the logcat from Android Studio: 这是来自Android Studio的logcat:

08-20 12:17:40.124      353-353/system_process I/ActivityManager: START u0 {act=SSO_WITH_FALLBACK cmp=com.my.app/com.facebook.LoginActivity (has extras)} from pid 30362
08-20 12:17:40.434      353-370/system_process I/ActivityManager: Displayed com.my.app/com.facebook.LoginActivity: +268ms
08-20 12:17:44.094      353-546/system_process I/ActivityManager: Start proc android.process.acore for content provider com.android.providers.contacts/.ContactsProvider2: pid=30500 uid=10014 gids={50014, 3003, 1015, 1028}
08-20 12:17:44.134  30500-30500/android.process.acore E/Trace: error opening trace file: No such file or directory (2)
08-20 12:17:45.494    353-12974/system_process I/ActivityManager: Process com.facebook.katana:dash (pid 30233) has died.

Any suggestion on my problem? 关于我的问题有什么建议吗?

EDIT: Here's the code of the main activity 编辑:这是主要活动的代码

public class MainActivity extends FragmentActivity {
    public static final boolean D = SystemConstants.ACTIVE_DEBUG;
    public static final String TAG = "MainActivity";

    private static final int SPLASH = 0;
    private static final int SELECTION = 1;
    private static final int FRAGMENT_COUNT = SELECTION +1;

    private Fragment[] fragments = new Fragment[FRAGMENT_COUNT];
    private boolean isResumed = false;
    private UiLifecycleHelper uiHelper;

    private Session.StatusCallback callback =
            new Session.StatusCallback() {
                @Override
                public void call(Session session, SessionState state, Exception exception) {
                    onSessionStateChange(session, state, exception);
                }
            };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        uiHelper = new UiLifecycleHelper(this, callback);
        uiHelper.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        FragmentManager fm = getSupportFragmentManager();
        fragments[SPLASH] = fm.findFragmentById(R.id.splashFragment);
        fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment);

        FragmentTransaction transaction = fm.beginTransaction();
        for (Fragment fragment : fragments) {
            transaction.hide(fragment);
        }
        transaction.commit();
    }

    /**
     * Configure files destinations.
     */
    private void configureEnvironment() {
        File sd = Environment.getExternalStorageDirectory();
        if (sd.canWrite()) {
            File destination = new File(sd, SettingConstants.BASE_DIR);
            if (!destination.mkdir() && !destination.isDirectory()) {
                Log.e(TAG, "Unable to create Base Directory.");
                Tracking.sendException(new IllegalStateException("Unable to create Base Directory."));
            }

            File audio = new File(sd, SettingConstants.AUDIO_DIR);
            if (!audio.mkdir() && !audio.isDirectory()) {
                Log.e(TAG, "Unable to create Audio Directory.");
                Tracking.sendException(new IllegalStateException("Unable to create Audio Directory."));
            }

            File avatar = new File(sd, SettingConstants.AVATAR_DIR);
            if (!avatar.mkdir() && !avatar.isDirectory()) {
                Log.e(TAG, "Unable to create Avatar Directory.");
                Tracking.sendException(new IllegalStateException("Unable to create Avatar Directory."));
            }

            File image = new File(sd, SettingConstants.IMAGE_DIR);
            if (!image.mkdir() && !image.isDirectory()) {
                Log.e(TAG, "Unable to create Image Directory.");
                Tracking.sendException(new IllegalStateException("Unable to create Image Directory."));
            }

            File video = new File(sd, SettingConstants.VIDEO_DIR);
            if (!video.mkdir() && !video.isDirectory()) {
                Log.e(TAG, "Unable to create Video Directory.");
                Tracking.sendException(new IllegalStateException("Unable to create Video Directory."));
            }

        }
    }

    /**
     * Shows a fragment
     * @param fragmentIndex
     * @param addToBackStack
     */
    private void showFragment(int fragmentIndex, boolean addToBackStack) {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        for (int i = 0; i < fragments.length; i++) {
            if (i == fragmentIndex) {
                transaction.show(fragments[i]);
            } else {
                transaction.hide(fragments[i]);
            }
        }
        if (addToBackStack) {
            transaction.addToBackStack(null);
        }
        transaction.commit();
    }

    /**
     * called due to session state changes. The method shows the relevant fragment based on the person's authenticated state.
     * @param session Facebook Session
     * @param state Facebook login state
     * @param exception Eventual exception
     */
    private void onSessionStateChange(Session session, SessionState state, Exception exception) {
        // Only make changes if the activity is visible
        if (isResumed) {
            FragmentManager manager = getSupportFragmentManager();
            // Get the number of entries in the back stack
            int backStackSize = manager.getBackStackEntryCount();
            // Clear the back stack
            for (int i = 0; i < backStackSize; i++) {
                manager.popBackStack();
            }
            if (state.isOpened()) {
                // If the session state is open:
                // Show the authenticated fragment
                showFragment(SELECTION, false);
            } else if (state.isClosed()) {
                // If the session state is closed:
                // Show the login fragment
                showFragment(SPLASH, false);
            }
        }
    }

    /**
     * case where fragments are newly instantiated and the authenticated versus nonauthenticated UI needs to be properly set.
     */
    @Override
    protected void onResumeFragments() {
        super.onResumeFragments();
        Session session = Session.getActiveSession();

        if (session != null && session.isOpened()) {
            // if the session is already open,
            // try to show the selection fragment
            showFragment(SELECTION, false);
        } else {
            // otherwise present the splash screen
            // and ask the person to login.
            showFragment(SPLASH, false);
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        Tracking.startActivityTracking(this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        Tracking.stopActivityTracking(this);
    }

    @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
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        uiHelper.onSaveInstanceState(outState);
    }
}

EDIT 2: Tried on the emulator gives the same error, given that the facebook APK is not installed it shows a webview, asks for login and then closes the activity. 编辑2:在模拟器上尝试给出相同的错误,因为未安装facebook APK,它会显示一个webview,要求登录,然后关闭活动。 I've added method tracing logging, the last call inside MainActivity is onDestroy ... 我添加了方法跟踪日志记录,MainActivity内部的最后一个调用是onDestroy ...

Just found the solution to this problem. 刚刚找到解决此问题的方法。

Make sure that you don't use 确保您不使用

android:noHistory="true"

in the manifest, relative to the MainActivity (In the given sample). 在清单中,相对于MainActivity(在给定的示例中)。

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

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