[英]Activity should run only once at the first run of the App in phone
我創建了一個名為activity_create_password的活動,該活動將在首次在單元格上啟動該應用程序時為該應用程序創建密碼,而在下一次以后,它將顯示名為activity_insert_password的活動。 我怎么能做到這一點我沒有得到請幫助。
您必須使用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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.