Serg Chernata
Serg Chernata

Reputation: 12400

Parse anonymous User ID doesn't persist on Android

I'm using anonymous users with parse but user ID keeps changing every time the app is restarted. I can create a serious of records, tied to a user and see them in backend / the app itself. Then kill the app, restart it and see a new user in Parse backend. Obviously, all records are no longer displayed because this is a "new user".

How can I make anonymous user id persist?

Upvotes: 4

Views: 1352

Answers (2)

Serg Chernata
Serg Chernata

Reputation: 12400

Turns out, if you're using Parse SDK and their anonymous users, you need to check if user is logged in and then run anonymous user initialization only in that case. Otherwise, each time the app is restarted, a new anonymous user is created. Makes sense but wasn't in their docs.

Upvotes: 4

Robert Rowntree
Robert Rowntree

Reputation: 6289

When you 'create' a new user, i think that you are getting an implied 'logon' of that new user.

Note that the response to the logon includes a session token ( no expiration on token ).

Using 'sharedPreferences' or some other android persistence technique, when you restart the app you can just retrieve the token from your persistence layer and - at least in REST API - just include that token in your headers along with AppId, and REST key and you will get that users data.

If you are using the SDK and not rest api, there may be some other way to get back to a reference for the user.

Upvotes: 0

Related Questions