当前位置: 动力学知识库 > 问答 > 编程问答 >

android - how to pass facebook object in intent?

问题描述:

I would like to implement an android app requires facebook login in the beginning. As I declare the facebook object in main activity and want to invoke facebook.authorize in another activity, but I can't put the facebook object to intent, is there other way to achieve this?

Here is the flow:

When the app is first opened, a main activity is opened. It will then check if the access token is set, if no, a new activity is started to let user login. In that activity there are some login option and a login button. If user press the login button, facebook api is called to do the login.

网友答案:

You can use a similar method that is used in the official facebook/android examples.
Using the SessionStore you can do something like:

First activity:

Facebook facebook = new Facebook("APP_ID");
if (!SessionStore.restore(facebook, this)) {
    // start the other activity for authentication
}

Second activity:

Facebook facebook = new Facebook("APP_ID");
facebook.authorize(this, new DialogListener() {
    @Override
    public void onComplete(Bundle values) {
        SessionStore.restore(facebook, this)
    }
    ...
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: