2013-08-27 46 views
0

我正在開發一個android應用程序,其中由用戶需要註冊/登錄,但這種方式很好,但是當用戶註銷時問題出在哪裏。註銷似乎並未真正註銷

當前當用戶按下注銷按鈕時,它會將它們帶回到登錄頁面,但是如果您離開應用程序並離開應用程序然後再回到應用程序(所以它仍在內存中)回到頁面,您在登錄後看到

我使用了一個sharedpreference記錄,如果用戶登錄或沒有,然後有一個飛濺活動這是第一件事情,開始決定要顯示的畫面。

public class Splash extends SherlockActivity { 
    public static final String PREFS_NAME = "PrefsFile"; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_splash); 

     SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); 
     boolean loggedin = settings.getBoolean("loggedIn", false); 
     if (loggedin){ 
      Intent intent = new Intent(this, MyLists.class); 
      startActivity(intent); 
     } 
     else{ 
      Intent intent = new Intent(this, LogIn.class); 
      startActivity(intent); 
     } 
    } 

}

然後我的註銷按鈕看起來像

private OnClickListener OnClick_logout = new OnClickListener() { 
     public void onClick(View v) { 
      SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); 
      SharedPreferences.Editor editor = settings.edit(); 
      editor.putBoolean("loggedIn", false); 
      editor.putString("email", ""); 
      editor.putString("password", ""); 
      editor.commit(); 
      db.clearLists(); 
      db.clearProducts(); 
      Intent intent = new Intent(v.getContext(), Splash.class); 
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      v.getContext().startActivity(intent); 
     } 
    }; 

按鈕被按下飛濺活動後,需要用戶在登錄屏幕當前但就像我說的,如果你再關閉應用程序,並回到它,它會採取用戶訪問'MyLists'活動。

+0

你的問題是什麼? – Santhosh

+0

如果您然後關閉應用程序並返回它,它將使用戶進入「MyLists」活動。沒有實際登錄 –

+1

你可以發佈'LogIn.java'中的代碼嗎? – Vikram

回答

0

您需要使用意向標誌清除堆棧歷史記錄。在您導航回到登錄屏幕,說

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

然後在後退按鈕上,您的應用程序退出。

此外,請確保將sharepreference變量清零或調用System.exit()。

P.S:調用system.exit()將使用戶每次登錄他/她想要使用該應用程序。

希望有幫助

+0

因此,如果我將這些標誌添加到註銷按鈕內的意圖它應該工作或? –

+0

是的,請嘗試讓我知道 –

+0

它仍然會執行相同的操作,當您回到應用程序時,它會直接進入mylists活動 –