0

I'm using the SearchView widget in the app bar for my project (single activity, no fragments, just used to filter a RecyclerView list based on the users input). That mechanism works as desired - but unfortunately I'm getting a bunch of IInputConnectionWrapper Warnings all related to closing this widget. Curiously, these errors even occur when starting with a clean, empty Android project.

Detailed Description

My activity consists of a RecyclerView, which contains Strings. When the search widget in the app bar is expanded and keyboard presses are detected, the view must be updated: The UI should only display elements that contain the users input, automatically on each keyboard button press. So far, no issues. But now I want to "finish" the search: When the user presses this green button on the keyboard, I want to: Hide the keyboard, clear the text in the search widget and close ("collapse") it. There seem to be several ways to achieve this, but all of them result in different variations of an InputConnection warning.

Steps to reproduce

  1. In Android Studio, create a New Project ("Empty Activity")

  2. Add a SearchView widget to the app bar as described here.

options_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/search"
        android:icon="@drawable/ic_search"
        android:title="@string/search_title"
        app:actionViewClass="android.widget.SearchView"
        app:showAsAction="ifRoom" />
</menu>
  1. Add a searchable.xml and update the Manifest.xml (as described here and here)
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/app_label"
    android:imeOptions="actionDone"
    android:hint="@string/search_hint" >
</searchable>
<application
        android:label="@string/app_name"
        android:theme="@style/Theme.MyApplication">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.SEARCH" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable" />
        </activity>
</application>
  1. Defining how the SearchView behaves, as described in here and here
override fun onCreateOptionsMenu(menu: Menu): Boolean {
    menuInflater.inflate(R.menu.options_menu, menu)

    val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager

    val searchView = menu.findItem(R.id.search).actionView as SearchView

    searchView.apply {
        setSearchableInfo(searchManager.getSearchableInfo(componentName))
    }

    searchView.setOnQueryTextListener(object: SearchView.OnQueryTextListener {
        override fun onQueryTextSubmit(query: String): Boolean {

            // here I want to clear and close the SearchView.
            // Unfortunately, it's not possible without warnings
            // Detailed description below

            return true
        }

        override fun onQueryTextChange(newText: String): Boolean {
            // after each letter input, update the View
            Log.i(MainActivity::class.java.toString(), newText)
            return true
        }
    })

    return true
}

What I've tried so far

There seem to be several ways for achieving what I want to. They all work, but all of them throw warnings at me.

1)

searchView.setQuery("", false)
if (!searchView.isIconified()) {
    searchView.setIconified(true);
}

output is

IInputConnectionWrapper: endBatchEdit on inactive InputConnection
searchView.onActionViewCollapsed()

output is

IInputConnectionWrapper: endBatchEdit on inactive InputConnection
val toolbar: Toolbar = findViewById<View>(R.id.toolbar) as Toolbar

toolbar.collapseActionView()

output is

endBatchEdit on inactive InputConnection
requestCursorAnchorInfo on inactive InputConnection
getTextBeforeCursor on inactive InputConnection
getTextBeforeCursor on inactive InputConnection
getTextBeforeCursor on inactive InputConnection
getTextBeforeCursor on inactive InputConnection
getTextBeforeCursor on inactive InputConnection
getTextBeforeCursor on inactive InputConnection
getTextBeforeCursor on inactive InputConnection
getTextBeforeCursor on inactive InputConnection
getTextBeforeCursor on inactive InputConnection
getTextBeforeCursor on inactive InputConnection
getSelectedText on inactive InputConnection
getTextBeforeCursor on inactive InputConnection
val closeButton: View = searchView.findViewById(androidx.appcompat.R.id.search_close_btn)
closeButton.callOnClick() // clears the input
closeButton.callOnClick() // close the widget

output is

IInputConnectionWrapper: endBatchEdit on inactive InputConnection

I think I've exhausted by now all options I have. What am I missing here? Any way of closing the searchView always results in at least one warning. I found some similar problem on SO (getExtractedText on inactive InputConnection warning on android), but here the issue occurs with an EditText element, and I'm not sure how to apply the solutions to a SearchView (or even whether that solution is relevant to my case.)

Qme
  • 1

0 Answers0