2013-10-01 61 views
2

我已經創建了一個活動叫activity_create_password當應用程序在首次和下一次細胞開始這將爲應用程序創建密碼起它應該顯示名爲activity_insert_password的活動。我怎麼能做到這一點我沒有得到請幫助。活動應在應用程序第一次運行在手機只運行一次

+4

商店標誌到像'isFirstRun'的喜好,將被默認TRUE;。第一次運行後將值更改爲「false」。在每次午餐中,你都應該檢查這個變量的值。並顯示/跳過活動取決於價值。 –

+1

使用共享偏好.. 創建2頁activity_create_password和activity_insert_password併爲您第一次運行則顯示activity_create_password頁別的activity_insert_password頁。 –

回答

1

你必須使用SharedPreferences來實現這一點,你的代碼應該是這樣

SharedPreferences prefs = mContext.getSharedPreferences("appName", 0); 
SharedPreferences.Editor editor = prefs.edit(); 
Intent intent; 
if (prefs.getBoolean("isInitialAppLaunch", false)) 
{ 
    intent = new Intent(this, activity_insert_password.class); 
    startActivity(intent); 
} 
else 
{ 
    //First Time App launched, you are putting isInitialAppLaunch to false and calling create password activity. 
    editor.putBoolean("isInitialAppLaunch", false); 
    intent = new Intent(this, activity_create_password.class); 
    startActivity(intent); 
} 
相關問題