Hello, Artur.
That’s not how it’s done. From what I see in your code, you want to use an input received from a search to extract the text typed in the search. The point is that you are not taking the instance of the Intent.getIntent(URI) received by the search, this method is not good for this. Your myIntent does not contain the query.
By default, when a user executes a query in the application, a new instance of your Activity is created and executed. You can get this information by calling the method getIntent()
in one of the Activity lifecycle methods, for example within the onCreate()
.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_funcionariostatus);
Intent myIntent = getIntent();
}
You can intercept the search engine before a new instance of your Activity is created and executed (I do not indicate this interception, because opening an instance for each search that the user performs is interesting to maintain a history and give the possibility to return to the previous search just by returning to the previous screens). This can happen in the Activity method startActivity(Intent intent)
that’s called every time you do startActivity(intent)
, which by the way is done automatically when the user executes the search. The incoming input in this method is the same that you would capture in onCreate()
making getIntent()
, for it is she is transferred to Activity which will be instantiated. Thus, you can do the check to confirm being the search engine and then do what you want. You will prevent a new Activity from being opened by preventing the father’s method from being called super.startActivity(intent);
, for it is he who will initiate the process of instantiation of the new Activity. Thus:
@Override
public void startActivity(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
//Do something with the query...
} else {
super.startActivity(intent);
}
}
I indicate the reading of this article: http://www.materialdoc.com/search-filter/
– Tássio Auad
Taxis, you must be light-year more experienced than I am, for I have not understood much of what you have said. But thank you anyway for your help. I entered the link you passed. There I could understand better. I will try.
– Artur Mafezzoli Júnior