簡體   English   中英

在手機上首次運行該應用程序時,活動只能運行一次

[英]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);
}

您應該使用SharedPreferences類來實現此目的。

請參閱下面的鏈接以使用共享首選項。

如何使用共享首選項

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM