According to program when i enter the correct credentials and click the log in button it should open the another activity and if i enter the wrong credentials it will show a toast message "Incorrect Credentials", but even if i write the correct credentials it still display toast message instead of redirecting to another activity`
`
package com.shivanshu.activitylifecycle
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
class NewActivity : AppCompatActivity(){
lateinit var etPhoneNumber: EditText
lateinit var etPassword : EditText
lateinit var btnLogIn: Button
lateinit var txtForgotPassword: TextView
lateinit var txtRegisterYourself: TextView
val validPassword = "8743950822"
val validPhoneNumber = "Tony"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_new)
title = "Log in"
etPhoneNumber = findViewById(R.id.etPhoneNumber)
etPassword = findViewById(R.id.etPassword)
btnLogIn = findViewById(R.id.btnLogIn)
txtForgotPassword = findViewById(R.id.txtForgotPassword)
txtRegisterYourself = findViewById(R.id.txtRegisterYourself)
btnLogIn.setOnClickListener{
val password = etPassword.getText().toString()
val phoneNumber = etPhoneNumber.getText().toString()
if((phoneNumber == validPhoneNumber) && (password == validPassword)){
val intent = Intent(this@NewActivity,MainActivity::class.java)
startActivity(intent)
}else {
Toast.makeText(
this@NewActivity,
"Incorrect Credentials",
Toast.LENGTH_LONG
).show()
}
}
}
}