I am not sure on how should the question be phrased , but the issue that i currently face is that why does my LoginActivity not show upon startup. Here is my code below
<activity
android:name=".MainActivity"
android:label="@string/title_activity_login"
android:theme="@style/Theme.TutorSeekers30.NoActionBar" ></activity>
<activity
android:name=".ForgetAccount"
android:label="@string/title_activity_forget_account"
android:theme="@style/Theme.TutorSeekers30.NoActionBar"></activity>
<activity
android:name=".SignupActivity"
android:label="@string/title_activity_signup"
android:theme="@style/Theme.TutorSeekers30.NoActionBar" ></activity>
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
so rightfully,in order to let the activity that you want to be shown first, you would have to replace what you want in the <activity android:name=".LoginActivity">
the one that is above the right? but after replacing, somehow my loginActivity is not the first screen shown. I have tried replacing both the forget account and signupActivity to be the first screen shown upon startup and both are displayed as intended. However, for my LoginActivity, it does not show up as the first screen intended. Why? Do i need to show other stuff here also?
so here is my LoginActivity:
public class LoginActivity extends AppCompatActivity {
EditText etUsername,etPassword;
Button btnLogin;
TextView tvForgetAccount,tvCreateAccount;
ProgressBar pbBar;
private FirebaseAuth auth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
auth = FirebaseAuth.getInstance();
if (auth.getCurrentUser() != null){
startActivity(new Intent(LoginActivity.this,MainActivity.class));
finish();
}
etPassword = findViewById(R.id.etPassword);
etUsername = findViewById(R.id.etUsername);
btnLogin = findViewById(R.id.Loginbutton);
tvCreateAccount = findViewById(R.id.tvCreateAccount);
tvForgetAccount = findViewById(R.id.tvForgetAccount);
pbBar = findViewById(R.id.progressBar2);
tvCreateAccount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(LoginActivity.this,SignupActivity.class);
startActivity(i);
}
});
tvForgetAccount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(LoginActivity.this,ForgetAccount.class);
startActivity(i);
}
});
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = etUsername.getText().toString();
final String password = etPassword.getText().toString();
if (TextUtils.isEmpty(username)){
Toast.makeText(getApplicationContext(),"Please enter your username",Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)){
Toast.makeText(getApplicationContext(),"Please enter your password",Toast.LENGTH_SHORT).show();
return;
}
pbBar.setVisibility(View.VISIBLE);
auth.signInWithEmailAndPassword(username,password).addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
pbBar.setVisibility(View.GONE);
if (!task.isSuccessful()){
if (password.length() < 6 ){
Toast.makeText(getApplicationContext(),"Wrong Password. Please try again",Toast.LENGTH_LONG).show();
return;
}else if (password.isEmpty()){
Toast.makeText(getApplicationContext(),"Password field cannot be empty",Toast.LENGTH_SHORT).show();
return;
}
} else{
Intent i = new Intent(LoginActivity.this,MainActivity.class);
startActivity(i);
finish();
}
}
});
}
});
};
}
here is my signUpActivity:
public class SignupActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
EditText etName,etPassword,etPhone,etEmail;
Button btnCreate;
private ProgressBar progressbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
mAuth = FirebaseAuth.getInstance();
etName = findViewById(R.id.editTextTextPersonName);
etPassword = findViewById(R.id.editTextTextPassword);
etPhone = findViewById(R.id.editTextPhone);
etEmail = findViewById(R.id.editTextTextEmailAddress);
btnCreate = findViewById(R.id.CreateButton);
progressbar = findViewById(R.id.progressBar);
btnCreate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
registerNewUser();
}
});
}
private void registerNewUser() {
progressbar.setVisibility(View.VISIBLE);
String email,password,username;
int ContactNumber ;
email = etEmail.getText().toString();
password = etPassword.getText().toString();
username = etName.getText().toString();
PhoneNumberUtils.formatNumber(etPhone.getText().toString());
if (TextUtils.isEmpty(email)){
Toast.makeText(getApplicationContext(),"Please Enter Email!",Toast.LENGTH_LONG).show();
return;
}
if (TextUtils.isEmpty(password)){
Toast.makeText(getApplicationContext(),"Please Enter Password!",Toast.LENGTH_LONG).show();
return;
}
if (TextUtils.isEmpty(username)){
Toast.makeText(getApplicationContext(),"Please Enter Username!",Toast.LENGTH_LONG).show();
return;
}
if (password.length() < 6){
Toast.makeText(getApplicationContext(),"Password too short , Please enter a minimum value of 6 characters",Toast.LENGTH_LONG).show();
return;
}
mAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
Toast.makeText(getApplicationContext(),"Registration is Successful!",Toast.LENGTH_LONG).show();
progressbar.setVisibility(View.GONE);
Intent intent = new Intent(SignupActivity.this,MainActivity.class);
startActivity(intent);
}
else{
Toast.makeText(getApplicationContext(),"Registration failed! " + " Please try Again ",Toast.LENGTH_LONG).show();
startActivity(new Intent(SignupActivity.this,MainActivity.class));
progressbar.setVisibility(View.GONE);
finish();
}
}
});
}
}
and here is my ForgetAccount
public class ForgetAccount extends AppCompatActivity {
EditText etUsername,etEmail;
Button btnSend;
private ProgressBar progressBar;
FirebaseAuth auth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forget_account);
etEmail = findViewById(R.id.editTextTextEmailAddress2);
etUsername = findViewById(R.id.etUsername);
btnSend = findViewById(R.id.Sendbutton);
progressBar = findViewById(R.id.progressBar2);
auth = FirebaseAuth.getInstance();
btnSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = etEmail.getText().toString().trim();
String username = etUsername.getText().toString();
if (TextUtils.isEmpty(email)){
Toast.makeText(getApplication(), "Enter your registered email id", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(username)){
Toast.makeText(getApplication(), "Enter your Username", Toast.LENGTH_SHORT).show();
return;
}
progressBar.setVisibility(View.VISIBLE);
auth.sendPasswordResetEmail(email).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()){
Toast.makeText(ForgetAccount.this,"We have sent instructions to your registered email",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(ForgetAccount.this,"Failed to send email!",Toast.LENGTH_SHORT).show();
}
progressBar.setVisibility(View.GONE);
}
});
}
});
}
}