我想讓一個用戶不需要再次登錄,一次登錄後。我的代碼不會跳過登錄頁面。如何跳過登錄頁面?我有一個開始頁面。我按開始按鈕,它進入登錄頁面。但是用戶已經登錄,使得跳過登錄頁面並轉到下一頁。 我該怎麼辦?如何讓用戶不需要再次登錄android
JSONObject json=null;
int status=2;
String userID=null;
String teamID=null;
String teamName=null;
String admin=null;
String backNo=null;
String userName=null;
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("email",edit_txt_EmailAddress.getText().toString()));//// define the parameter
postParameters.add(new BasicNameValuePair("password",edit_txt_Password.getText().toString()));
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads().detectDiskWrites().detectNetwork() // StrictMode is most commonly used to catch accidental disk or network access on the application's main thread
.penaltyLog().build());
ArrayList<NameValuePair> pp = new ArrayList<NameValuePair>();
//postParameters.add(new BasicNameValuePair("userID","396797666"));
String response = null;
try {
response=CustomHttpClient.executeHttpPost("http://10.0.2.2/kwikwi/login.php", postParameters);
json=new JSONObject(response);
userID=json.getString("userID");
}
catch (Exception e) {
e.printStackTrace();
}
Log.i("USERID", userID+"");
JSONObject json_data = null;
String teamStatus ="";
String result = response.toString();
JSONObject jsonobj = null;
try{
jsonobj = new JSONObject (result);
teamStatus=jsonobj.getString("teamStatus");
}
catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
Log.i("TeamStatus", result+"");
Log.i("RESULT", teamStatus+"");
//Log.i("halo",teamStatus+"");
String[] teamSaving=new String[6];
String[] noteamSaving=new String[2];
if (blNagSetting == true){
if(teamStatus.equals("1")){
try {
Log.i("Team Kyaw Win tal","Log in ma twar buu.");
userName=jsonobj.getString("userName");
userID=jsonobj.getString("userID");
teamID=jsonobj.getString("teamID");
teamName=jsonobj.getString("teamName");
admin=jsonobj.getString("admin");
backNo=jsonobj.getString("backNo");
teamSaving[0]=userName;
teamSaving[1]=userID;
teamSaving[2]=teamID;
teamSaving[3]=teamName;
teamSaving[4]=admin;
teamSaving[5]=backNo;
Log.i("USerName", userName+"");
Log.i("UserID",userID+"");
Log.i("TeamId",teamID+"");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent teamshi=new Intent(Login.this,Team.class);
teamshi.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(teamshi);
finish();
}
else if(teamStatus.equals("0"))
{
try {
Log.i("NoTeam Kyaw Win tal","Log in ma twar buu.");
userName=jsonobj.getString("userName");
userID=jsonobj.getString("userID");
noteamSaving[0]=userName;
noteamSaving[1]=userID;
Log.i("USerNameNN", userName+"");
Log.i("UserIDNN",userID+"");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent noteamshi=new Intent(Login.this,NoTeam.class);
noteamshi.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(noteamshi);
finish();
}
}else
{
if(teamStatus.equals("1")){
try {
Log.i("Team Win tal","Log in hmar");
userName=jsonobj.getString("userName");
userID=jsonobj.getString("userID");
teamID=jsonobj.getString("teamID");
teamName=jsonobj.getString("teamName");
admin=jsonobj.getString("admin");
backNo=jsonobj.getString("backNo");
teamSaving[0]=userName;
teamSaving[1]=userID;
teamSaving[2]=teamID;
teamSaving[3]=teamName;
teamSaving[4]=admin;
teamSaving[5]=backNo;
Log.i("USerName", userName+"");
Log.i("UserID",userID+"");
Log.i("TeamId",teamID+"");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
editor = prefsNagSetting.edit();
editor.putBoolean(NAG_SETTING, true);
editor.commit();
Intent teamshi=new Intent(Login.this,Team.class);
teamshi.putExtra("TeamSaving", teamSaving);
startActivity(teamshi);
}
else if(teamStatus.equals("0"))
{
try {
Log.i("noTeam Win tal","Log in hmar");
userName=jsonobj.getString("userName");
userID=jsonobj.getString("userID");
noteamSaving[0]=userName;
noteamSaving[1]=userID;
Log.i("USerNameNN", userName+"");
Log.i("UserIDNN",userID+"");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
editor = prefsNagSetting.edit();
editor.putBoolean(NAG_SETTING, true);
editor.commit();
Intent noteamshi=new Intent(Login.this,NoTeam.class);
noteamshi.putExtra("NoTeamSaving", noteamSaving);
startActivity(noteamshi);
}
else{
showAlertDialog(Login.this,"Invalid Email and Password", "Enter Valid Email and Password", false);
}
}
}
這是我的代碼。
public void onClick(View arg0) {
// TODO Auto-generated method stub
isInternetPresent = conDetector.isConnectingToInternet();
Boolean save=false;
if (isInternetPresent){
isLoggedIn();
saveLoggedIn(save);
if (isLoggedIn()){
Intent team= new Intent(MainActivity.this,Team.class);
startActivity(team);
}
else{
Intent goLogin=new Intent(MainActivity.this,Login.class);
startActivity(goLogin);
}
}
else{
showAlertDialog(MainActivity.this, "No Internet Connection",
"You don't have internet connection.", false);
}
}
});
}
private boolean isLoggedIn() {
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(this);
//The false represents the default value, if the variable is not stored
boolean isLoggedIn = sharedPreferences.getBoolean("isLoggedIn", false);
return isLoggedIn;
}
private void saveLoggedIn(boolean value) {
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(this);
Editor editor = sharedPreferences.edit();
editor.putBoolean("isLoggedIn", value);
editor.commit();
}
這是我的編輯代碼。
我已經使用了共享首選項,但我沒有看到是記住你說...編輯器怎麼樣......如果你知道,請告訴我關於這個,plz。 – vcav