1. Are you ready for the Galaxy S20? Here is everything we know so far!

Login app just terminate whenever it starts.

Discussion in 'Android Development' started by farter, Jul 29, 2021.

  1. farter

    farter Lurker
    Thread Starter

    upload_2021-7-29_18-38-0.png
    I made a layout like this (Two EditTexts ,Two buttons.), and codes are below .

    class RegisterActivity: AppCompatActivity() {

    private lateinit var mFirebaseAuth: FirebaseAuth
    private lateinit var mEdID: EditText
    private lateinit var mEdPW: EditText

    override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
    super.onCreate(savedInstanceState, persistentState)
    setContentView(R.layout.activity_login)

    mFirebaseAuth = Firebase.auth
    mEdID = findViewById<EditText>(R.id.editTextID)
    mEdPW = findViewById<EditText>(R.id.editTextPW)

    //registration button
    btn_register.setOnClickListener {
    val strEmail = mEdID.getText().toString()
    val strPW = mEdPW.getText().toString()

    mFirebaseAuth.createUserWithEmailAndPassword(strEmail, strPW)
    .addOnCompleteListener(this) { task ->
    if (task.isSuccessful()) {
    Log.w(TAG, "successful registration")
    val firebaseuser = mFirebaseAuth.currentUser
    } else {
    Log.w(TAG, "registration failed", task.exception)
    Toast.makeText(baseContext, "registration failed",
    Toast.LENGTH_SHORT).show()
    }
    }
    }

    //login button
    btn_login.setOnClickListener{
    val strEmail = mEdID.getText().toString()
    val strPW = mEdPW.getText().toString()

    mFirebaseAuth.signInWithEmailAndPassword(strEmail,strPW)
    .addOnCompleteListener(this) { task->
    if(task.isSuccessful()){
    Log.d(TAG, "successful login")
    val user = mFirebaseAuth.currentUser
    }else{
    Log.w(TAG, "login failed", task.exception)
    Toast.makeText(baseContext, "login failed.",
    Toast.LENGTH_SHORT).show()
    }
    }
    }
    }
    }

    I wrote codes in onCreate , and the app just terminate whenever activity start.
    I don't know why this happens.
     



    1. Download the Forums for Android™ app!


      Download

       
  2. Sumbul

    Sumbul Lurker

    If you are in Makkah and Planning to visit Makkah. then you must know these 10 things to buy in mecca. This article will guide you about the exploring Makkah and what you should buy from there
     
Loading...

Share This Page

Loading...