2016-01-22 76 views
0

使用Quickblox聊天,當我關閉應用程序時,如何銷燬會話?這樣當我下次啓動應用程序時,它應該可以登錄進行聊天。Quickblox Chat會話問題

我曾嘗試在調用deleteSession的onDestroy我的MainActivity的,但它似乎犯規幫助。

@Override 
public void onDestroy() { 
    super.onDestroy(); 
    QBUsers.signOut(new QBEntityCallbackImpl() { 
     @Override 
     public void onSuccess() { 
      Log.v("SESSION","Session logout"); 
      ChatService.getInstance().removeConnectionListener(chatConnectionListener); 
      QBAuth.deleteSession(new QBEntityCallback<Void>() { 
       @Override 
       public void onSuccess(Void aVoid, Bundle bundle) { 
        Log.v("SESSION","Session destroyed"); 

       } 

       @Override 
       public void onSuccess() { 
        Log.v("SESSION","Session destroyed 2"); 
        //i get success here, when i onDestroy is called 

       } 

       @Override 
       public void onError(List<String> list) { 
        Log.v("SESSION",list.toString()); 
       } 
      }); 
     } 

     @Override 
     public void onError(List errors) { 
      Log.v("SESSIONERROR",errors.toString()); 
     } 
    }); 
} 

現狀:

當我啓動應用程序,它得到了Quickblox會話,並登錄到聊天。 但如果我關閉該應用程序。下一次當我啓動應用程序,它會得到Quickblox會議,並在那裏卡住。

我需要從任務管理器中殺死應用程序,並啓動應用程序登錄。

SDK迴應時,我改弦更張

01-23 23:04:07.017 21733-21733/? D/ChatService: Initialise QBChatService 
01-23 23:04:07.027 21733-21733/? D/QBASDK: ========================================================= 
              === REQUEST ==== 66f6e80c-9319-48c6-8d55-374d83c715e2 === 
              REQUEST 
               POST https://api.quickblox.com/session.json 
              HEADERS 
               QuickBlox-REST-API-Version=0.1.1 
               QB-SDK=Android 2.3.3 
              PARAMETERS 
               application_id=xxxx 
               auth_key=U48ZQsXad2OcBNa 
               nonce=-855163362 
               timestamp=1453570447 
               user[login]=egun1234 
               user[password]=egun1234 
               signature=f3edc13692c8ad3d4aae90717be7c05890ea4780 
              INLINE 
               POST https://api.quickblox.com/session.json?application_id=xxxxx&auth_key=U48ZQsXad2OcBNa&nonce=-855163362&timestamp=1453570447&user[login]=egun1234&user[password]=egun1234&signature=f3edc13692c8ad3d4aae90717be7c05890ea4780 
01-23 23:04:12.047 21733-21733/? D/QBASDK: ********************************************************* 
              *** RESPONSE *** 66f6e80c-9319-48c6-8d55-374d83c715e2 *** 
              STATUS : 201 
              HEADERS 
               Access-Control-Allow-Origin=* 
               Cache-Control=max-age=0, private, must-revalidate 
               Connection=keep-alive 
               Content-Length=270 
               Content-Type=application/json; charset=utf-8 
               Date=Sat, 23 Jan 2016 17:34:01 GMT 
               ETag="b6aee90833f76c7e670ffb4b24a8a7a5" 
               QB-Token-ExpirationDate=2016-01-23 19:34:01 UTC 
               QuickBlox-REST-API-Version=0.1.1 
               Server=nginx/1.6.2 
               Status=201 Created 
               Strict-Transport-Security=max-age=15768000; 
               X-Rack-Cache=invalidate, pass 
               X-Request-Id=e42acfadd6cb14f5b396587c0d837551 
               X-Runtime=0.035198 
               X-UA-Compatible=IE=Edge,chrome=1 
              BODY 
               '{"session":{"_id":"56a3b989a0eb471c5a00000f","application_id":xxxx,"created_at":"2016-01-23T17:34:01Z","device_id":0,"nonce":-855163362,"token":"767c6cadc31c5e6c45ba64ef29d45a9b28a2bd0d","ts":1453570447,"updated_at":"2016-01-23T17:34:01Z","user_id":7748679,"id":42627}}' 
01-23 23:04:12.127 21733-21757/? D/QBASDK: Connecting to chat.. 
01-23 23:04:15.127 21733-21757/? D/QBASDK: Connected. Login to chat, currentUser JID: 7748679-xxxxx, resource: 811ee375c6eff567 

SDK迴應時,我只是關閉應用程序並重新啓動(應用程序仍然在任務管理器)

01-23 23:14:40.617 21733-21733/? D/QBASDK: ========================================================= 
              === REQUEST ==== ed61d1eb-a18d-4ba9-b730-8b552e5e46bc === 
              REQUEST 
               POST https://api.quickblox.com/session.json 
              HEADERS 
               QuickBlox-REST-API-Version=0.1.1 
               QB-SDK=Android 2.3.3 
               QB-Token=767c6cadc31c5e6c45ba64ef29d45a9b28a2bd0d 
              PARAMETERS 
               application_id=xxxxx 
               auth_key=U48ZQsXad2OcBNa 
               nonce=1359179285 
               timestamp=1453571080 
               user[login]=egun1234 
               user[password]=egun1234 
               signature=f99dda85c65db5aff212512939fed7408f14461e 
              INLINE 
               POST https://api.quickblox.com/session.json?application_id=xxxxx&auth_key=U48ZQsXad2OcBNa&nonce=1359179285&timestamp=1453571080&user[login]=egun1234&user[password]=egun1234&signature=f99dda85c65db5aff212512939fed7408f14461e 
01-23 23:14:48.657 21733-21733/? D/QBASDK: ********************************************************* 
              *** RESPONSE *** ed61d1eb-a18d-4ba9-b730-8b552e5e46bc *** 
              STATUS : 201 
              HEADERS 
               Access-Control-Allow-Origin=* 
               Cache-Control=max-age=0, private, must-revalidate 
               Connection=keep-alive 
               Content-Length=270 
               Content-Type=application/json; charset=utf-8 
               Date=Sat, 23 Jan 2016 17:44:37 GMT 
               ETag="778f1e9b028ecb55f5d5aaf210f22c5f" 
               QB-Token-ExpirationDate=2016-01-23 19:44:37 UTC 
               QuickBlox-REST-API-Version=0.1.1 
               Server=nginx/1.6.2 
               Status=201 Created 
               Strict-Transport-Security=max-age=15768000; 
               X-Rack-Cache=invalidate, pass 
               X-Request-Id=9d23abaa4c411a42bb466a65c9aa78bc 
               X-Runtime=0.041888 
               X-UA-Compatible=IE=Edge,chrome=1 
              BODY 
               '{"session":{"_id":"56a3bc05a0eb47f007000097","application_id":xxxxx,"created_at":"2016-01-23T17:44:37Z","device_id":0,"nonce":1359179285,"token":"3fdf2abc49d381c5827db4647bade2c51db9b64d","ts":1453571080,"updated_at":"2016-01-23T17:44:37Z","user_id":7748679,"id":42501}}' 

回答

1

沒有必要做任何事情會議或登錄在的onDestroy的onResume只是把支票飛濺活動解決了我的問題。

@Override 
    protected void onResume() { 
     super.onResume(); 
     if (isChatLoggedIn()) { 
      decideLaunchActivity(); 
      finish(); 
     } 
    } 
    private boolean isChatLoggedIn() { 
     return QBChatService.isInitialized() && QBChatService.getInstance().isLoggedIn(); 
    } 
1

不要做這種類型的編碼。

這裏您正在onDestroy()內部進行異步請求。在這種情況下,onDestroy()中的代碼即使在完成onDestroy()的執行後也會繼續運行(直到完成QBUsers.signOut()的執行),因爲代碼是異步運行的。因此,您需要將此代碼放入按鈕單擊中,並在signOut成功時退出您的應用程序。

+0

它只在日誌中打印結果一次。我在代碼中提到過。我沒有讓你的積分代碼將繼續運行。它成功刪除會話。但是,我無法啓動應用程序,直到我從taskmanager中殺死應用程序實例。它登錄到quickblox並在獲得會話後卡住...不能登錄到聊天。 – Veer3383

+0

明顯它只會打印一次結果。 –

+0

我沒有明白你的觀點 - 我的意思是說,代碼將繼續運行,直到signOut()完成執行,當signOut()完成時代碼的執行將停止,它不會一次又一次地運行。 –