本文介绍了如何保持用户登录的应用程序的生命?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题,以保持用户登录我所有的应用程序生命,登录是主要的活动,当启动另一个活动我仍然在loged,我可以上传数据quickblox,但之后,我开始另一个活动,然后重新开始,我上传数据quickblox的activy,我得到错误,当尝试上载数据:令牌是必需的......

编辑:

  QBSettings.getInstance()fastConfigInit(将String.valueOf(APP_ID),AUTH_KEY,AUTH_SECRET)。
    QBUser用户=新QBUser(登录,密码);
    QBAuth.createSession(用户,这一点,QBQueries.SIGN_IN);


解决方案

我认为这是另外一个问题。

符号的要求的意思是你没有创建会话,并试图执行其他查询

您必须先正确地创建一个会话

  QBAuth.createSession(新QBCallbackImpl(){
            @覆盖
            公共无效的onComplete(结果结果){
                如果(result.isSuccess()){
                    //做其他的要求在这里
                    //
                }其他{
                    handleErrors(结果);
                }
            }
        });

如果这不是你的问题 - 请提供更多code在你的问题。

UPD

1)请检查令牌为空

  {尝试
    。字符串标记= BaseService.getBaseService()为gettoken();
    如果(令牌== NULL){
        //此处重建会议
    }
}赶上(BaseServiceException E){
    e.printStackTrace();
}

i'm having problem to keep the user sign in for all my app life, the "sign in" is on the main activity, when start another activity i'm still loged in and i can upload data to quickblox, but after i start another activity and then start again the activy that i uploaded data to quickblox, i get error when try to upload data: "token is required"...

Edit:

 QBSettings.getInstance().fastConfigInit(String.valueOf(APP_ID), AUTH_KEY, AUTH_SECRET);
    QBUser user = new QBUser("login", "password");
    QBAuth.createSession(user, this, QBQueries.SIGN_IN);
解决方案

I think it's another issue

"token is required" means that you didn't create session and trying to perform other query

You have to properly create a session first

        QBAuth.createSession(new QBCallbackImpl() {
            @Override
            public void onComplete(Result result) {
                if (result.isSuccess()) {
                    // do other requests here
                    //
                } else {
                    handleErrors(result);
                }
            }
        });

If it's not an issue for you - please provide more code in your question

UPD

1) Try to check token for null

try {
    String token = BaseService.getBaseService().getToken();
    if(token == null){
        // recreate session here
    }
} catch (BaseServiceException e) {
    e.printStackTrace();
}

这篇关于如何保持用户登录的应用程序的生命?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 17:39