Start a new topic

Keeping a user logged in


I'm having an issue keeping a user logged in. The first screen of my app has a check whether the user is logged in already or not. If he's not, then the app gives him the necessary menus to do so. If he is, the app lets him go to the second screen. The second screen has some logic for saving/fetching data.

- If I make a fresh installation of the app, it asks me to log in, and then lets me go to the second screen. Everything works nicely there.

- If I then leave the app ("Home" button), remove it from the "Recently used" list and start it again - it allows me to go to the second screen straight away. But any saving/fetching logic doesn't work.

- After a while the app realizes that I'm not logged in and starts giving errors on saving/fetching. Or, if I'm not in the app, then on restart it'll offer me the login screen.

It looks like it looses the cached user data or something like that, if the app gets closed. Could you please help me solve this issue? Ideally, I want to keep the user logged in, regardless of whether he had restarted the app or not.


So i had some very similar issues with this. I will say though that mine was on iOS so not sure how the android works but I figured I would give my two cents anyway.

The issue I had was that Kinvey created a implicit user if I have no user logged in. Even though an implicit user is not a "user", Kinvey would consider it a user. So when I made the call to check to see if i am logged in it would say yes because the implicit user counted as a logged in person. The way I "fixed" it because in my case there was no way to tell if it was a implicit user or explicit user is I created a guest account which had a object ID I could reference. I could then check in the start is this a guest user? if so they cannot do any calls to the database otherwise I no the current credentials that are stored are a explicit user so I can continue with writing and reading.

Hope this helps,

Hey Sean,

Thank you for the advice. I'll check if that's acceptable in our case.

I wonder whether the support team has any extra info on the issue.
Are you clearing the app's data at any point? Or maybe modifying the user object via the console?

once a user has logged in, the android library will store their auth token and user id on disk. When a client is built, first it will try to load these saved credentials and ensure the auth token is still valid-- if it is, then you are good to go but if the auth token has been revoked than the client will be logged out.

Note that the client confirms stored credentials asynchronously, so there is a delay while waiting for the network request.

To access callbacks for this login, you can set a KinveyUserCallback on the builder-- this callback's onSuccess or onFailure method will be called when the client has automatically logged in (or failed to log in) the stored credentials.

Client c = new Client.Builder(getApplicationContext()).setRetrieveUserCallback(new KinveyUserCallback() { ...}).build();

Login or Signup to post a comment