2011-03-23 48 views
1

這是我的場景:在訪問多個活動之後,用戶從應用程序註銷並重定向到登錄頁面。我想要的是如果用戶在登錄頁面時按回按鈕。我希望我的應用程序退出/關閉,而不是返回到之前的活動Android註銷並退出

有關此問題的任何建議?謝謝。

回答

1

...或者當活動開始,你可以查看登錄狀態:如果用戶沒有登錄,帶他到登錄界面...

+0

偉大的想法,奇怪的是有沒有想到這一點。儘管異步任務可能會在註銷時保持運行。 – manmal 2011-09-24 17:03:12

0

重寫onBackPressed,其中調用android.os.Process.killProcess(android.os.Process.myPid())

3

只需將此代碼寫入您的註銷按鈕的OnClickListener的OnClick方法即可。

Intent intent = new Intent(getApplicationContext(),Login.class); 
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(intent); 

它適用於我。 祝你好運。

0

我已經使用的onResume對驗證活動的方法,如用戶連接:

@Override 
protected void onResume() { 
    super.onResume(); 

    ParseUser currentUser = ParseUser.getCurrentUser(); 

    if (currentUser == null) { 
     finish(); 
    } 
} 
0

我實現下一個方式這種行爲。 創建退出類:

class LogOut { 
    void addOnLogoutListener(LogoutListener listener); 
    void removeOnLogoutListener(LogoutListener listener); 
    void logout(); 
} 

這是一個全球性的類。 當用戶想要註銷時,他應該調用logout()方法 - 此方法通知每個監聽器。 在您的活動中添加完成活動的偵聽器。我總是在BaseActivity類中添加這樣的偵聽器來刪除代碼重複。 同樣在App類中,您可以定義啓動LoginActivity的偵聽器,或者在註銷發生時清除重要資源。

0

寫上您的登錄活動回壓法

Intent startMain = new Intent(Intent.ACTION_MAIN); 
    startMain.addCategory(Intent.CATEGORY_HOME); 
    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    startActivity(startMain);