-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
78 lines (63 loc) · 2.4 KB
/
Copy pathMainActivity.java
File metadata and controls
78 lines (63 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.example.bibek.userlogin;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import java.util.Objects;
public class MainActivity extends AppCompatActivity {
EditText username1,password1;
Button login,signup;
CheckBox remmember;
boolean check;
SharedPreferences sharedPreferences;
SharedPreferences.Editor editor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sharedPreferences = getSharedPreferences("prefName",MODE_APPEND);
editor = sharedPreferences.edit();
username1 = (EditText)findViewById(R.id.username);
password1 = (EditText)findViewById(R.id.password);
login = (Button)findViewById(R.id.login);
signup = (Button)findViewById(R.id.signup);
remmember = (CheckBox)findViewById(R.id.chbox);
check = sharedPreferences.getBoolean("check",false);
if(check)
{
remmember.setChecked(true);
Intent i1 = new Intent(this,LoginActivity.class);
startActivity(i1);
}
}
public void onLogin(View view)
{
String userName = username1.getText().toString();
String passWord = password1.getText().toString();
String username = sharedPreferences.getString("username",null);
String password = sharedPreferences.getString("password",null);
if(remmember.isChecked()) {
editor.putBoolean("check", true);
editor.apply();
}
if((userName.equals(username))==true && (passWord.equals(password))==true){
/*editor = sharedPreferences.edit();
editor.putString("userName",userName);
editor.putString("passWord",passWord);
editor.apply();*/
Intent i = new Intent(this, LoginActivity.class);
startActivity(i);
}
else
Toast.makeText(this,"Incorrect UserName or Password",Toast.LENGTH_SHORT).show();
}
public void onSignUp(View view){
Intent intent = new Intent(this,SignUpActivity.class);
startActivity(intent);
}
}