我正试图创建和安乐,要求用户认证(通过教育、科学和技术部的网络服务)。 该软件有多种活动和屏幕,所有这些活动都要求用户贴上标签,在用户中贴上标签,可以在网站上增加和编辑员额。
I have read that using a AndroidHttp Client within a "ConnectionManager" singleton would be the best way to do it. However where would I go about storing the users details (username, password), would this be in the singleton? Should I authenticate each time the user try s to edit/add something?
Should I have a class like this:
public class ConnectionManager {
private static ConnectionManager instance = null;
private AndroidHttpClient client;
private ConnectionManager() {
client = AndroidHttpClient.newInstance("Android-Connection-Manager");
}
public static ConnectionManager getInstance() {
if( instance == null ) {
instance = new ConnectionManager();
}
return instance;
}
public void authenticate(String username, String password) {
//Check for authentication here
}
}
并且每当用户做些什么时,即使用以下代码:
private static ConnectionManager conn = ConnectionManager.getInstance();
conn.authenticate();
<>>>>
should I store the users details in the singleton
public class ConnectionManager {
private static ConnectionManager instance = null;
private AndroidHttpClient client;
private AppUser mLoggedInUser;
private boolean mAuthenticated;
private ConnectionManager() {
client = AndroidHttpClient.newInstance("Android-Connection-Manager");
}
public static ConnectionManager getInstance() {
if( instance == null ) {
instance = new ConnectionManager();
}
return instance;
}
public void InitialiseUser(String username, String password) {
//Do login checks here then return true if logged in
mAuthenticated = true;
}
public boolean isAuthenticated() {
return mAuthenticated;
}
}