2

I am trying to write simple app which uses Samsung Pass and/or Google Auth, but both of them doesn't work despite of proper settings on my device. Popup for saving password and username doesn't show. Other apps works good on my device with Samsung Pass/Google Auth.

Below my layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:importantForAutofill="yes"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/username"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:autofillHints="username"
        android:hint="username"
        android:inputType="text"
        android:importantForAutofill="yes" />

    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:autofillHints="password"
        android:hint="password"
        android:importantForAutofill="yes"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/loginButton"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="Zaloguj"
        app:layout_constraintTop_toBottomOf="@+id/password" />

</LinearLayout>

and activity:


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        loginButton.setOnClickListener {
            if (checkCredentials(username.text.toString(), password.text.toString())) {
                val intent = Intent(this, LoggedInActivity::class.java)
                startActivity(intent)
            }
        }
    }

    private fun checkCredentials(username: String, password: String): Boolean {
        return (username.isNotEmpty() && password.isNotEmpty())
    }
}

What am I doing wrong?

Jastine
  • 135
  • 2
  • 13

1 Answers1

0

Ok, found the reason - finish() must be called after starting new activity.

    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    loginButton.setOnClickListener {
        if (checkCredentials(username.text.toString(), password.text.toString())) {
            val intent = Intent(this, LoggedInActivity::class.java)
            startActivity(intent)
            finish()
        }
    }
}
Jastine
  • 135
  • 2
  • 13