2

Facebook 開発者の次のガイドに従って、Facebook 3.0 SDK のログインを使用しようとしています: https://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/

私の問題は、ユーザーがログイン ボタンをクリックすると、アクティビティが終了し、Facebook のプロセスが停止することです。

これは 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.

私の問題に関する提案はありますか?

編集:メインアクティビティのコードは次のとおりです

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);
    }
}

編集 2: Facebook APK がインストールされていない場合、エミュレーターで試してみると同じエラーが発生し、webview が表示され、ログインが要求され、アクティビティが閉じられます。メソッド トレース ログを追加しました。MainActivity 内の最後の呼び出しはonDestroy ...

4

1 に答える 1

1

この問題の解決策を見つけました。

使用していないことを確認してください

android:noHistory="true"

MainActivity に関連するマニフェスト内 (指定されたサンプル内)。

于 2013-08-20T15:13:36.190 に答える