2014-06-06 51 views
0

我正在創建一個名爲「MainActivity.class」的活動,我在其中進行登錄,並在下一個活動中進行註銷。Android - 登錄後維護會話無需註銷

獲取日誌後,我維護會話使用sessionmanager.class在其中我使用的方法checklogin()。

在mainactivity中,我使用了session.checklogin()方法,因爲哪個應用程序不是由於堆問題而啓動的。 如果我不使用上述方法,會話不會得到維護。

請協助我維護會議。

下面是從sessionmanager類checklogin代碼() -

public void checkLogin() { 
    // Check login status 
    if (this.isLoggedIn()) { 
     // user is logged in redirect him to Login Activity 
     Intent i = new Intent(_context, Home.class); 
     // Closing all the Activities 
     i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     // Add new Flag to start new Activity 
     i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     // Staring Login Activity 
     _context.startActivity(i); 
    } else 
     if (!this.isLoggedIn()) { 
     // user is not logged in redirect him to Login Activity 
     Intent i = new Intent(_context, FirstActivity.class); 
     // Closing all the Activities 
     i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     // Add new Flag to start new Activity 
     i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     // Staring Login Activity 
     _context.startActivity(i); 

    } 

} 

在MainActivity.class,我使用 -

SessionManager會話; (),我正在做 - 會話=新的SessionManager(getApplicationContext()); 然後傳遞session.checklogin();

+0

使用共享PREF實現這一目標。 – Dev

回答

0

三點需要清除。

1.可以通過使用Android中的共享首選項來管理權限。它可以用來將數據存儲爲鍵值對。
2.一旦你的應用程序完成服務器通信,那麼不會有任何會話使它活着。
3.SessionManager類實際上並不用於維護會話。它將媒體會話作爲隊列來管理。

請參閱以下文檔。這將有所幫助。
共享偏好
http://developer.android.com/reference/android/content/SharedPreferences.html
SessionManaget http://developer.android.com/samples/MediaRouter/src/com.example.android.mediarouter/player/SessionManager.html