开发应用,需要判断用户是不是第一次进入程序,首次进入需要注册,不是第一次进入,直接跳转到第二个界面

思路:将标志位存储起来,进入应用的时候读取判断,如果为默认值,则首次进入,如果已经设置过了,则不为首次进入。

上代码:

SharedPreferences setting;
final String INITIALIZED = "initialized";
Boolean user_first;

String phonenum1=null;
String phonenum2=null;

    public void signUp(View view) {
        phonenum1 = ((EditText) findViewById(R.id.et_phonenum1))
                          .getText().toString();
        phonenum2= ((EditText) findViewById(R.id.et_phonenum2))
                          .getText().toString();
        //whether input is phone number
        if (!Patterns.PHONE.matcher(phonenum1).matches()) {
            Toast.makeText(this, R.string.invalid_phonenum, Toast.LENGTH_SHORT).show();
            return;
        }
        //whether the two numbers are the same
        if (!phonenum1.equals(((EditText) findViewById(R.id.et_phonenum2))
                             .getText().toString())) {
            Toast.makeText(this, R.string.inconsistent_phonenum,
                           Toast.LENGTH_SHORT).show();
            return;
        }
    Intent intent=new Intent(this, MainActivity.class);
    intent.putExtra("PHONE_NUM", phonenum2);
    startActivity(intent);
        finish();
    }

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
  this.requestWindowFeature(Window.FEATURE_NO_TITLE);//move the title

setting=getSharedPreferences("setting", 0);打开Preferences,名称为setting,如果存在则打开它,否则创建新的Preferences

user_first = setting.getBoolean("FIRST",true);//取得相应的值,如果没有该值,说明还未写入,用true作为默认值  

    if(user_first){
    //第一次登录,正常加载
    setContentView(R.layout.activity_sign_up);
   
    }else{

//如果不是第一次登录,直接跳转到下一个界面
    Intent intent=new Intent(this, MainActivity.class);
    startActivity(intent);
    finish();
    }

        setting.edit().putBoolean("FIRST", false).commit();


}

更多相关文章

  1. Android(安卓)N及以上版本应用安装包下载完成自动弹出安装界面的
  2. Android(安卓)Studio技能之快捷键
  3. Android初级教程_内存分析工具MemoryAnalizer
  4. Android(安卓)UI 使用HTML布局(直接打开服务器网页)
  5. Android在代码中打开Wifi、移动网络和GPS
  6. [Android(安卓)界面] setContentView和inflate区别
  7. Robotium-无源码测试
  8. Android调试工具Genymotion的使用
  9. Android判断现在所处界面是否为home主桌面的方法

随机推荐

  1. 利用html制作一个课程表与注册表
  2. JQuery学习之$.get、$.post、$.ajax的应
  3. 学习正式起步
  4. DOM型漏洞测试
  5. HULK容器镜像仓库简介
  6. 300行Go代码玩转RPC
  7. 浅谈Kubernetes Service负载均衡实现机制
  8. 从理论-实战,手把手带你图解微服务架构流
  9. 服务器中watchdog挖矿病毒排查方法
  10. Go进阶:如何开发多彩动感的终端UI应用