Created
June 29, 2017 13:29
-
-
Save chris-carneiro/6df6e4fb29e63a222841c631df95bc48 to your computer and use it in GitHub Desktop.
Simple token manager for android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TokenManager { | |
| private static final String TAG = TokenManager.class.getName(); | |
| private static TokenManager instance; | |
| private String token; | |
| private TokenManager() { | |
| token = ""; | |
| } | |
| /** | |
| * Init manager of Token | |
| */ | |
| public static void init() { | |
| if(null==instance) { | |
| instance = new TokenManager(); | |
| } | |
| } | |
| public static TokenManager getInstance() { | |
| return instance; | |
| } | |
| /** | |
| * Update value of TOKEN. | |
| * @param token token | |
| */ | |
| public void setToken(String token) { | |
| this.token = token; | |
| } | |
| /** | |
| * Retieve current token | |
| * | |
| * @return Token | |
| */ | |
| public String getToken(){ | |
| return token; | |
| } | |
| /** | |
| * Indicate if we have a token | |
| * | |
| * @return true / false | |
| */ | |
| boolean hasToken(){ | |
| Log.d(TAG,"TOKEN : "+token); | |
| return null!=token && !"".equals(instance.token); | |
| } | |
| /** | |
| * Remove current token | |
| */ | |
| void clearToken(){ | |
| token = null; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment