function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Madhu DkMadhu Dk 

How to keep user logged in all time

How to keep user logged in all time?

Hi,

I am using Android App, in which i am using WebView to open salesforce url.
After logging in, if i close app and open it after few hours (6hr) it will ask me to login again.
How to make it logged in all time.
Best Answer chosen by Madhu Dk
Todd Halfpenny MCTodd Halfpenny MC
Ah right, so you've built your own custom app without using the SDK and are just accessing the org via the webView. In this case you're "browser session" will be handled by the platform just as if you were going direct via a browser. It could be your access token TTL (time to live) is set to 6 hours on the platform.

If you're building a custom app and want to have persistant session then I believe you'll need to use the oauth flow to get an access token (and refresh token) that can be used to authenticate/validate the user. The mobile SDK has calls for this (but can also be quite heavy). At MobileCaddy (http://tps://mobilecaddy.net) we use a variant of the SDK to acheive full persistant login to the org for our custom apps.

All Answers

Todd Halfpenny MCTodd Halfpenny MC
Is this a custom app built with the Salesforce Mobile SDK?
If so it might be that your access token as expired, in which case you will need to use the refresh token flow (https://developer.salesforce.com/docs/atlas.en-us.mobile_sdk.meta/mobile_sdk/oauth_refresh_token_flow.htm).
Madhu DkMadhu Dk
Is this a custom app built with the Salesforce Mobile SDK? - No
I am opening the org url inside WebView.
 
Todd Halfpenny MCTodd Halfpenny MC
Ah right, so you've built your own custom app without using the SDK and are just accessing the org via the webView. In this case you're "browser session" will be handled by the platform just as if you were going direct via a browser. It could be your access token TTL (time to live) is set to 6 hours on the platform.

If you're building a custom app and want to have persistant session then I believe you'll need to use the oauth flow to get an access token (and refresh token) that can be used to authenticate/validate the user. The mobile SDK has calls for this (but can also be quite heavy). At MobileCaddy (http://tps://mobilecaddy.net) we use a variant of the SDK to acheive full persistant login to the org for our custom apps.
This was selected as the best answer
vasumati gumpulavasumati gumpula
Thanks for the code. Its working fine.
for more such useful tricks
Way to Hunt (https://waytohunt.org/)
Elitetricks (https://elitetricks.net)