+ Start a Discussion
Stefan FellnerStefan Fellner 

Login Validation - Android SDK

Hello,

I have the following objective regarding to the login process of my android based salesforce app:

Depending on a user has been logged in / out or rather his login data (authToken,...) is still valid / invalid, I want to trigger different mechanisms.

Is it a save way if I check on the currently logged in UserAccount to be !null / null, like this:

UserAccount loggedInUserAccount = SmartSyncSDKManager.getInstance().getUserAccountManager().getCurrentUser();
if (loggedInUserAccount != null) {
   //Trigger mechanism 1
} else {
  //Trigger mechanism 2
}

Thank you in advance
stefan
Gaurav KheterpalGaurav Kheterpal
Why would you want to sue the SmartSyncSDKManager class for this?

I think you can simply do
 
ClientInfo ci =this.client.getClientInfo();
String userId = ci.userId;
If the user Id is not null, you have a valid session. Makes sense?

If my answer helps resolve your query, please select it as a 'Best Answer' so that it benefits others and helps us improve the overall quality of the forums.

 
Stefan FellnerStefan Fellner
Hi Gaurav,

the reason why I can not use the RestClient, is the fact that I am not extending the SalesforceActivity and therefore do not get the client through onResume(RestClient restClient) method.

My goal is to know if the user needs to log in or not, before going to the login screen. With the above described approach it seems to work out well. I am just not confident that this is reliable in case e.g. the access token expires.

Thank you for clarifying on that!
Stefan
Gaurav KheterpalGaurav Kheterpal
Not sure but a good way to test is to lower the timeout value and test it.