Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalStateException: focus search returned a view that wasn't able to take focus! #21563

Closed
sentry-io bot opened this issue Jan 7, 2025 · 6 comments · Fixed by #21566
Closed

IllegalStateException: focus search returned a view that wasn't able to take focus! #21563

sentry-io bot opened this issue Jan 7, 2025 · 6 comments · Fixed by #21566
Assignees

Comments

@sentry-io
Copy link

sentry-io bot commented Jan 7, 2025

Sentry Issue: JETPACK-ANDROID-12YC

IllegalStateException: focus search returned a view that wasn't able to take focus!
    at android.widget.TextView.onKeyUp(TextView.java:9701)
    at android.view.KeyEvent.dispatch(KeyEvent.java:2958)
    at android.view.View.dispatchKeyEvent(View.java:15760)
    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1986)
    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1986)
...
(48 additional frame(s) were not displayed)
@dangermattic
Copy link
Collaborator

dangermattic commented Jan 7, 2025

Thanks for reporting! 👍

@nbradbury
Copy link
Contributor

Possibly helpful

@nbradbury
Copy link
Contributor

nbradbury commented Jan 7, 2025

Looking at the crash reports, the problem occurs in SiteCreationActivity, but it may also occur in:

  • PostSignupInterstitialActivity
  • LoginEpilogueActivity
  • ChooseSiteActivity

@nbradbury
Copy link
Contributor

From Gemini:

Summary

The app crashed because a TextView failed to take focus when the focus search mechanism tried to give it focus during a key up event. This happened inside an onKeyUp method of a TextView. The stack trace shows that the key event traveled through a complex view hierarchy, including a NestedScrollView, before reaching the problematic TextView. The presence of NestedScrollView suggests that there might be scrollable content involved. This crash is an IllegalStateException, which indicates an unexpected internal state within the Android framework.

Potential Solutions

Check focusable and focusableInTouchMode attributes: The most likely cause is that the TextView which the focus search landed on was not actually focusable. Ensure that the TextView in question has both the android:focusable="true" and android:focusableInTouchMode="true" attributes set in its XML layout or programmatically. focusableInTouchMode is particularly important if the user is interacting with the UI using touch.

<TextView
    ...
    android:focusable="true"
    android:focusableInTouchMode="true" />

Alternatively, ensure these are set programmatically:

textView.setFocusable(true);
textView.setFocusableInTouchMode(true);

Inspect Focus Handling Logic within NestedScrollView: The presence of androidx.core.widget.NestedScrollView in the stack trace suggests potential issues with focus handling within scrollable content. Verify that the layout within the NestedScrollView is set up correctly to manage focus transitions, especially when items are scrolled on or off-screen. Pay attention to any custom focus handling logic you might have implemented. You may want to look for potential calls to requestFocus() or overrides of onKeyUp, onKeyDown, or dispatchKeyEvent to see if your code interferes with the normal process of determining focus. If there is custom focus handling, validate that the code correctly accounts for all possible view states and always returns a focusable view when calling requestFocus().

Review Key Event Handling: Although less likely, an issue with your custom key event handling could be contributing to the problem. If you have overridden methods like onKeyUp, onKeyDown, or dispatchKeyEvent in any of your Activities, Fragments, or custom Views, particularly those within or related to the NestedScrollView, double-check the logic within these methods. Make sure that your handling doesn't interfere with the standard Android focus mechanisms. If your custom handling returns true when an event is not fully processed, it can short-circuit the normal focus search and lead to this type of error. Consider removing custom handling if not absolutely necessary.

@nbradbury
Copy link
Contributor

I was finally able to reproduce this crash. It's happening in our domain registration fragment:

  • From the My Site tab, tap to change sites
  • Choose Add a site
  • Choose Create WordPress.com site
  • Skip choosing a topic or theme
  • When you get to Choose a domain, search for a domain ("Test" works fine)
  • Scroll down then tap the Search button on the soft keyboard
  • Boom!
crash.mp4

@nbradbury
Copy link
Contributor

Closed via #21566

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants