活动应在应用程序的手机第一次运行只运行一次 [英] Activity should run only once at the first run of the App in phone

查看:97
本文介绍了活动应在应用程序的手机第一次运行只运行一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个名为活动activity_create_password这将创建密码的应用程序时,应用程序启动的单元上的第一次,下次开始就应该表现出活动命名activity_insert_password。我怎么能做到这一点我没有收到请帮助。

I have created an activity named activity_create_password which will create password for the app when the application is started on the cell for the first time and next time onwards it should show the activity named activity_insert_password. how can I achieve this I am not getting Please Help.

推荐答案

您必须使用共享preferences 来实现这一目标,您的code应该像

You have to use SharedPreferences to achieve this, your code should be something like

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);
}

这篇关于活动应在应用程序的手机第一次运行只运行一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆