- Home /
Problem is not reproducible or outdated
Android keyboard pauses app, and doesn't release it
Hello.
I'm confused by the workings of the Android keyboard. When opened, it seems to pause the Unity execution (no Update functions getting called etc). That would be acceptable (though not optimal, because I want to show the typed text in a text field), but it doesn't even seem to release this lock when closed!
Below is a very simple bit of example code. If I run this on the Android device, I get debug lines only up to the point when I tap the screen to open the keyboard. After that, no matter what I do, it never gets into the Update function again. Except, if I press the Home button and resume the app via multitasking, it does resume.
public class AnroidKeyboardTester : MonoBehaviour {
private TouchScreenKeyboard keyboard;
public void Update(){
Debug.Log("Update: " + Time.frameCount);
if (Input.GetMouseButtonDown(0)){
keyboard = TouchScreenKeyboard.Open("test", TouchScreenKeyboardType.Default, false, false, false, false);
}
}
}
Edit: one line does appear in the log once I press the "OK" button on the Android keyboard:
windowFocusChanged: true
It changes to false when I open the keyboard. So I think this focus is supposed to change back, but it's not actually changing...
I think you're supposed to use the keyboard inside OnGUI() not in Update(), but I haven't tested it.
Thanks for the suggestion. I tested it, however, and it doesn't seem to make a difference.
Answer by skylem · Feb 23, 2015 at 12:11 PM
here you go buddy, u just need to switch it on/off using a lone boolean the following should work for you
if(Input.GetMouseButtonDown(0) && !kb) {
kb = true;
}
else if(Input.GetMouseButtonDown(0) && kb) {
kb = false;
}
if(kb) {
keyboard = TouchScreenKeyboard.Open("test", TouchScreenKeyboardType.Default, false, false, false, false);
}
u will probably need some additional code(my knowledge on touchscreen technology is virtually non existant) however i have noticed that there is also
TouchScreenKeyboard.visible = true/false;
perhaps this is useful to ur situation. if it doesn't work let me know and i'll do some research.
Thanks for the suggestion. I'll try that later just to be sure, but I don't see how that could work, since the program never gets into the Update function again once it has opened the keyboard. (So it would never get to the point where it switches kb back to false.
ah i totally forgot about that issue when i wrote my answer, yes i meant to suggest that if update is failing assu$$anonymous$$g u have tried FixedUpdate and LateUpdate aswell rather then initiate your keyboard use StartCoroutine and see if this is also failing an example of coroutine below
void Update () {
if(!kb || kb) {
StartCoroutine(Jump());
}
}
IEnumerator Jump () {
if(!kb) {
Debug.Log("Off");
}
if(kb) {
yield return new WaitForSeconds(0.5f);
Debug.Log("On");
}
}
applogies totally forgot about that issue while i was writing my answer i meant to suggest a coroutine example below
void Update () {
if(!kb || kb) {
StartCoroutine(Jump());
}
}
IEnumerator Jump () {
if(!kb) {
Debug.Log("Off");
}
if(kb) {
yield return new WaitForSeconds(0.5f);
Debug.Log("On");
}
}
it is odd that Update is Failing i've literally never encountered this issue which surprises me i suggest testing on multiple devices just to be sure that your device is not the cause of the problem, i don't know why it would be but it is certainly possible.
I tested all of FixedUpdate, Update, LateUpdate, and a coroutine. None of them are executed after the Android keyboard opens.
Also (added to main question too): one line does appear in the log once I press the "O$$anonymous$$" button on the Android keyboard:
windowFocusChanged: true
It changes to false when I open the keyboard. So I think this focus is supposed to change back, but it's not actually changing...
Your answer
Follow this Question
Related Questions
Android hardware keyboard 0 Answers
Remove "Preview text line" above keyboard input text on Android and iPhone 1 Answer
Wierd Sprite Error Keyboard taking sprite area 1 Answer
Receiving UI/touch events while mobile soft keyboard is open 0 Answers
Numpad Keypress not being registered on mobile phone. 0 Answers