I understand the search in android. In the application, 2 activations are created, one main, the other for searching. In the fragment attached to the activation base, I call the getActivity (). OnSearchRequested () method, in the search activation I catch the query and display the result in the Recycler. How can I now return the selected element of recycler to the fragment where the search began from, if I did not call startActivityForResult ()?
1 answer
It’s best to start the activation through startActivityForResult (), but since you cannot do this, for example, set the first activation in the manifest launch_mode="singleTop" and start it after selecting it with the completion of the activation with search. At the same time in the Intent put the necessary data. In theory, the first activation onNewIntent() call onNewIntent() and there you can pull out the transferred data and update the info on the screen ..
Judging by the en-SO, you need to set the base activity as an activit for searching in the manifest. After that, call from it a real search startActivityForResult() through startActivityForResult() and then act as usual with returning the result via setResult()
- Well, it turns out he starts the activation specified in the manifest. `<meta-data android: name =" android.app.default_searchable "android: value =". ui.activity.SearchActivity "/>` It turns out you can make the current active search and set this flag, then why need a second? - shagi
- @shagi, apparently you are going to use search activation a bit differently than its creators planned. An option for you is added in response - YuriySPb ♦
- This is my first acquaintance with search activity. What is the main idea of search activity then? just to display the found information? Just an idea, it seems, is simple: you search for something with the help of a search - when you find what you want, return to yourself and use ... - shagi
- @shagi, I have never dealt with it myself and why it is needed - without a clue) - YuriySPb ♦