Hello everyone i am working with http://quickblox.com/developers/Sample-webrtc-android its works fine
But i want know that is there any way to keep user logged in as quick blox user in my app.
Because right now everytime user open my app user have to login first so i want to keep session alive if it is possible android,
Because its better to do for performance instead of everytime login just prevent to login and keep session alive
Thanks in advance
I have used below code
private void createSession(final String login, final String password) {
final QBUser user = new QBUser(login, password);
QBAuth.createSession(login, password, new QBEntityCallbackImpl<QBSession>() {
@Override
public void onSuccess(QBSession session, Bundle bundle) {
Log.d(TAG, "onSuccess create session with params");
user.setId(session.getUserId());
if (chatService.isLoggedIn()) {
initQBRTCClient();
} else {
chatService.login(user, new QBEntityCallbackImpl<QBUser>() {
@Override
public void onSuccess() {
Log.d(TAG, "onSuccess login to chat");
/*
* ListUsersActivity.this .runOnUiThread(new
* Runnable() {
*
* @Override public void run() {
* showProgress(false); } });
*
* startCallActivity(login);
*/
islogin = true;
initQBRTCClient();
}
@Override
public void onError(List errors) {
Toast.makeText(HomeAppActivity.this, "Error when login", Toast.LENGTH_SHORT).show();
for (Object error : errors) {
Log.d(TAG, error.toString());
}
}
});
}
}
@Override
public void onError(List<String> errors) {
Toast.makeText(HomeAppActivity.this, "Error when login, check test users login and password",
Toast.LENGTH_SHORT).show();
}
});
}
As described in documentation session token is valid for 2 hours.
Once you have logged, you can store session token & expiration time somewhere in app storage - preference, database, etc. Token can be retrieved by
BaseService.getBaseService().getToken().
When user opens your app again, you can set session using stored tokenBaseService.createFromExistentToken()
Here is the documentation. Also to keep running permanently chat connection it’s better to use android service.