I am implementing an application that requires user authentication with server and is used to sync data between the android client and a server. After the first successful login I want to keep the access token in the AccountManager so that I don't have to always re-ask the user for credentials input. I have my own Account to accomplish this, of course. So as you might have guessed, if you don't have access token for that type of Account( the first login or some other problem to access the user credentials) I will show the Login Activity as starting one, otherwise I would show another one, which follows the Login Activity, in case I have token in the AccountManager. Any help on how to implement this?

Thank you.

有帮助吗?

解决方案

Here are two potential ways that you could go about doing this, though there are doubtless many others:

  1. Create a new launch activity that will look and determine whether you have a valid access token in your persistent storage. If not, launch the login activity. If so, take the user into the main part of the app.

  2. Keep the login activity as your app's launch activity, but before actually displaying the form, check whether you have a valid access token. Then, if a valid token is present, push the user straight through to the next screen.

In both cases, assuming that your token is stored locally on the device in some fashion, the process should happen so quickly as to be essentially invisible to the user.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top