SEPARATE RESPONSE
I myself experienced this problem, and I had to rely on the decision made by the solution. However, I noticed that there is a noticeable lag when entering into the Global Search field. This lag:
- Caused by the application, since its removal makes the backlog disappear.
- Most likely due to the synchronous wait in the requested applications - since our application performs two network requests, the
query() method takes time to complete, resulting in a lag
I found out that a separate process ( :androidtv ) is not needed. By setting the ThreadPolicy.LAX configuration, the network request will be executed without the NetworkOnMainThreadException metadata.
I still do not understand why there is a backlog.
ORIGINAL RESPONSE
I do not believe that the accepted answer, although it certainly works, is the right way.
After calling the query() method, you must create a new thread / task / task to make a network call (therefore, avoiding NetworkOnMainThreadException ), which will update the adapter after receiving the desired data.
There are different ways to do this. You can use a callback or an event bus (e.g. Otto ). This is the method I call to update the adapter:
public void updateSearchResult(ArrayList<Data> result) { mListRowAdapter.clear(); mListRowAdapter.addAll(0, result); HeaderItem header = new HeaderItem(0, "Search results", null); mRowsAdapter.add(new ListRow(header, mListRowAdapter)); }
source share