Resetting the counter upon new searches

Now we just need to reset the counter whenever a new search is started. This could be done in the Searcher class before starting a search, or when the button on the UI is clicked. Because our counter is thread-safe, either of those options should work fine.

Let's reset the counter when the search button is clicked in SearchActivity, as part of the click listener already being set during onCreate():

findViewById<Button>(R.id.searchButton).setOnClickListener {
viewAdapter.clear()
launch {
ResultsCounter.reset()
search()
}
}

Now, upon further testing, you will find that the counter is reset before each search.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.195.111