Integrating app searchability

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.

How to do it...

Integrating search into our app is very easy, only requiring a search activity and a few attributes on the activities:

  1. 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); ...

Get Xamarin Mobile Development for Android Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.