2013-04-21 99 views
0

我在android中製作一個應用程序,它在菜單中有多個選項,並且需要在每個選項中進行登錄信息,所以我想讓用戶只簽署一次而不是每次他選擇其中一個像facebook應用程序這樣的選項,即使當應用程序在後臺運行時,我也只需登錄一次,但它不會註銷。 sry 4很長的解釋,但我甚至不知道用於搜索此問題的關鍵字。如何在Android應用程序中登錄一次?

你能幫我嗎? 感謝ü

回答

4

一旦用戶輸入登錄憑據第一次,然後使用SharedPreferences和值isLogged設置爲1

當用戶打開應用程序時,如果此變量值爲'1',則檢查此變量,然後打開家庭活動。

SharedPreferences sharedPref = getSharedPreferences("data",MODE_PRIVATE); 
int number = sharedPref.getInt("isLogged", 0); 
if(number == 0) { 
    //Open the login activity and set this so that next it value is 1 then this conditin will be false. 
    SharedPreferences.Editor prefEditor = sharedPref.edit(); 
    prefEditor.putInt("isLogged",1); 
    prefEditor.commit(); 
} else { 
     //Open this Home activity 
} 
+0

ThnQ這麼多,我的工作完美:) – 2013-04-21 11:04:38

+0

我能問你另一個追求。 因此,當我需要註銷時,我只會使用此代碼或應使用其他代碼? {finish(); System.exit(0);} – 2013-04-21 11:06:53

+0

@NaneesNabil註銷後再將此變量值設置爲0。 – 2013-04-21 11:20:13

相關問題