Aldi Renaldi Gunawan Aldi Renaldi Gunawan - 3 months ago 21
Android Question

How to run background process to check if user session is End

i was try to create login session with session key, the session key always generate new key either we do Login/registration, i can retrieve the data from my gson

LoginService loginService = retrofit.create(LoginService.class);
Observable<LoginResponse> obs = loginService.logins(emai,pass,"1", Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID), Build.MODEL, Build.VERSION.RELEASE);
subscribe(new Observer<LoginResponse>() {
public void onCompleted() {


public void onError(Throwable e) {


public void onNext(LoginResponse loginResponse) {
int responses = loginResponse.getCODE();
String texts="";
if(responses == 1)
User user = loginResponse.getDATALIST().get(0);

the question is, how to make handler to handle the save session check if there is another login activity with the same account?


You should never assign two accessToken/Session for one user. You will send the same accessToken to the other instance of the new user. Plus side, user won't be able to duplicate his/her work by two accessToken.

If you want to force the other/first one AUTO-LOGOUT, you can use Firebase notification feature to send a notification to that particular deviceID and force it to stop. You can check firebase's tutorial to see how they work. Another slow procedure is to check before login & everyother server side work to check if there are instance of same user. You will send an error and user end will receive it and show the error accompanying by logging out the user.