Many apps work with collections of data, and users search through that data in order to find what they are looking for. Android has several search mechanisms that are integrated with the OS.
Integrating search into our app is very easy, only requiring a search activity and a few attributes on the activities:
In order to handle searching, our app has to have an activity that will handle search intents:
public class SearchActivity : Activity { protected override void OnCreate(Bundle bundle) { ... HandleIntent(Intent); } protected override void OnNewIntent(Intent intent) { HandleIntent(intent); } private void HandleIntent(Intent intent) { if (intent.Action == Intent.ActionSearch) { string query = intent.GetStringExtra(SearchManager.Query); } } }
Because Xamarin.Android will hash the type namespaces when it generates the Java code, we have to let it know what name we want for the search activity using the
[Register...