android创建的第一个用户,android - 如何在Android中创建多个用户注册和登录活动? - 堆栈内存溢出...

我已经使用共享首选项在android中进行了注册和登录活动。 用户能够成功注册和登录。 但是我的问题是当新用户注册时,它删除了前一个用户的注册详细信息。

这是我的注册页面:

public class Registration extends Activity implements

View.OnClickListener

{

SharedPreferences pref;

Editor editor;

TextView btn_registration , btn_formlogin;

EditText et_name, et_pass, et_email , et_phone ;

ImageView btn_upload ;

private static final int PICK_IMAGE_REQUEST = 0;

private Uri mImageUri;

SessionManager session;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_registration);

et_name = (EditText) findViewById(R.id.edt_Name);

et_pass = (EditText) findViewById(R.id.edt_userPassword);

et_email = (EditText) findViewById(R.id.edt_userEmail);

et_phone = (EditText) findViewById(R.id.edt_Phone);

btn_registration = (TextView) findViewById(R.id.btn_registration);

btn_formlogin = (TextView) findViewById(R.id.btn_formlogin);

btn_upload = (ImageView)findViewById(R.id.img_upload);

Map values = new HashMap();

AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

btn_upload.setOnClickListener(this);

SharedPreferences preference =

PreferenceManager.getDefaultSharedPreferences(this);

final String mImageUri = preference.getString("image", null);

btn_upload.setImageResource(R.drawable.adduser);

// creating an shared Preference file for the information to be stored

// first argument is the name of file and second is the mode, 0 is

private mode

pref = getSharedPreferences("USER_CREDENTIALS", 0);

// get editor to edit in file

editor = pref.edit();

// the tap of button we will fetch the information from four edittext

btn_registration.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick (View v) {

boolean validName = true;

boolean validPass = true;

boolean validPhone = true;

boolean validEmail = true;

String name = et_name.getText().toString();

String email = et_email.getText().toString();

String pass = et_pass.getText().toString();

String phone = et_phone.getText().toString();

if (isEmpty(et_name)) {

et_name.setError("Enter the Name");

validName = false;

}

if (isEmpty(et_pass)) {

et_pass.setError("Password can't be null");

validPass = false;

}

if (isEmail(et_email) == false) {

et_email.setError("Enter valid email");

validEmail = false;

}

if (isValidMobile(et_phone) == false) {

validPhone = false;

}

final String required_email= pref.getString("Email",null);

final String required_phone=pref.getString("Phone",null);

if(et_email.equals(required_email)){

validEmail = true;

}

else if(et_phone.equals(required_phone)){

validPhone = true;

}

if (validName && validPass && validPhone && validEmail){

// as now we have information in string. Lets stored them

with the help of editor

editor.putString("Name" , name );

editor.putString("Email", email);

editor.putString("Password", pass);

editor.putString("Phone", phone);

editor.putString("image", String.valueOf(mImageUri));

editor.commit(); // commit the values

Toast.makeText(Registration.this, "Registration

Successful", Toast.LENGTH_LONG).show();

session = new SessionManager(getApplicationContext());

session.createLoginSession(name, email, mImageUri);

// after saving the value open next activity

Intent ob = new Intent(Registration.this,

DashBoard.class);

startActivity(ob);

}

else{

Toast.makeText(Registration.this, "Registration

unsuccessful! Please retry.", Toast.LENGTH_LONG).show();

}

}

});

我只想知道如何使用共享的首选项文件注册多个用户?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值