在手机中首次运行应用程序时,活动应该只运行一次

时间:2013-10-01 05:11:58

标签: java android android-layout android-activity

我创建了一个名为activity_create_password的活动,当第一次在单元格上启动应用程序时,该活动将为应用程序创建密码,下次应该显示名为activity_insert_password的活动。我怎么能做到这一点我没有得到请帮助。

2 个答案:

答案 0 :(得分: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);
}

答案 1 :(得分:0)

您应该使用SharedPreferences类来实现此目的。

请参阅以下链接以使用共享偏好。

How to use shared preferences