Quickblox通过意图服务创建会话

时间:2015-10-20 14:07:26

标签: android quickblox intentservice android-intentservice

我正在尝试使用Alarm安排AlarmManager尝试每两小时重新创建一次QuickBlox会话。我通过IntentService在后​​台呼叫AlarmManager

以下是崩溃的代码:

protected void onHandleIntent(Intent intent)
{
    String APP_ID = "xxxx";
    String AUTH_KEY = "xxxx";
    String AUTH_SECRET = "xxxx";
    QBSettings.getInstance().fastConfigInit(APP_ID, AUTH_KEY,AUTH_SECRET);
    if (!QBChatService.isInitialized()){
        QBChatService.init(getApplicationContext());
    }

    ChatService.getInstance().chatCreateWriteSessionWithoutPlay(getApplicationContext());}

chatCreateWriteSession的定义如下:

public void chatCreateWriteSessionWithoutPlay(final Context ctx) {
        chatService = QBChatService.getInstance();
        // Create QB user
        final QBUser user = new QBUser();

        user.setLogin(AppController.getInstance().getCHAT_ID());
        user.setPassword(AppController.getInstance().getCHAT_PASSWORD());
        QBAuth.createSession(user, new QBEntityCallbackImpl<QBSession>() {
            @Override
            public void onSuccess(QBSession session, Bundle args) {

            }

            @Override
            public void onError(List<String> errors) {

            }
        });
    }

1 个答案:

答案 0 :(得分:1)

在QBEntityCallback中返回结果的所有方法都在主Ui线程上执行它。只需使用同步类型的方法,如QBSession session = QBAuth.createSession(QBUser用户),就可以在android服务启动的同一个线程上返回结果。