I have two methods that fire the Unity Event for that input field, try to save the input field value into a variable and then give that value back to Input Field when back button is pressed, but it doesn’t work on Android. It works just fine with Unity Editor
public string passwordHolder = “”;
public void OnEditting()
{
if (Application.platform == RuntimePlatform.Android)
{
if (!Input.GetKeyDown(KeyCode.Escape))
{
passwordHolder = passwordText.text;
}
}
}
public void OnEndEdit()
{
if (Application.platform == RuntimePlatform.Android)
{
if (Input.GetKeyDown(KeyCode.Escape))
{
passwordText.text = passwordHolder;
}
}
}
The “Input” does not work as normal when the keyboard is open. So you can not do the check you do with the “ESC” / back button.
What I have done is creating a method to listen to an event of the keyboard status changing. If it is going to hide (Canceled), I keep the previous text in the field.
I add the script to the object with the InputField component and this is the code that I have put in “Start”: