-1

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

    }
}
  • how do you know it isn't showing up ? are you setting the right content for this activity ? – a_local_nobody Mar 20 '21 at 13:35
  • What exception you're getting? – Saddan Mar 20 '21 at 13:40
  • @Saddan this question doesn't seem to be about any exceptions. it's just saying the wrong content is being shown. – a_local_nobody Mar 20 '21 at 13:47
  • @a_local_nobody. yea im pretty sure that the content is the right one. i know that it isint showing is because the design that i had for my login activity isint showing up at all whereas for the other two activities it is showing up as intended :( –  Mar 20 '21 at 13:56
  • @a_local_nobody. do i need to show anything else? :/ –  Mar 20 '21 at 13:56
  • 1
    `do i need to show anything else?` you need to show enough for me to recreate the problem. at the moment you have a manifest but you haven't posted your activities, so i don't know if the setContentView is actually correct – a_local_nobody Mar 20 '21 at 14:03
  • Check your run configuration in Android studio, next to where you click to run the app there is a drop-down menu to select or edit run configuration, make sure it has LoginActivity set. https://stackoverflow.com/a/30106306/6798074 – Ahmed AlAskalany Mar 20 '21 at 14:05
  • did you check your LoginActivity's `setContentView` which layout you're inflating there?what a_locall_nobody is mentioned pretty much possible – Saddan Mar 20 '21 at 14:10
  • @a_local_nobody. sorry about that there! I have made the changes –  Mar 20 '21 at 14:22
  • if auth.getCurrentUser() is not null it goes to the MainActivity have you looked at that one closely? – Eyosiyas Mar 20 '21 at 14:24
  • @Eyosiyas. Ah dam haha , now its working as intended! Thanks for your help! –  Mar 20 '21 at 14:32
  • Don't mention it. I'm glad it worked as you wanted. – Eyosiyas Mar 20 '21 at 14:38

1 Answers1

2

Adding the same Theme attribute into each Activity is redundant and useless. To make it globally useable the Theme attribute is declared in the application tag. The rest of the Manifest files should look like this.

       <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.TutorSeekers30.NoActionBar">

        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_login" />
        <activity
            android:name=".ForgetAccount"
            android:label="@string/title_activity_forget_account"/>
        <activity
            android:name=".SignupActivity"
            android:label="@string/title_activity_signup"/>

        <activity android:name=".LoginActivity">
            <intent-filter>
                 <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
       </activity>
Eyosiyas
  • 1,422
  • 1
  • 9
  • 25