Skip to content

Instantly share code, notes, and snippets.

@chris-carneiro
Created June 29, 2017 13:29
Show Gist options
  • Save chris-carneiro/6df6e4fb29e63a222841c631df95bc48 to your computer and use it in GitHub Desktop.
Save chris-carneiro/6df6e4fb29e63a222841c631df95bc48 to your computer and use it in GitHub Desktop.
Simple token manager for android
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