You can define (optionally) an abstract class that extends Activity, implements onSearchRequest, and inherits all other Activity classes from this class. Therefore, you should only define onSearch behavior once.
i.e.
public abstract class MyBaseActivity extends Activity { @Override public void onSearchRequest() {
If you plan to use several subclasses of Activity, i.e. ListActivity, this may not be a good solution, since you need to create an abstract base class for all Activity subclasses that you use. In this case, I would recommend creating an additional class by encapsulating the search button processing code and calling it from your onSearchRequest actions, i.e.
public class SearchButtonHandle { public void handleSearch(Context c) {
Of course, you can also combine both approaches by defining an abstract subclass of all activity subclasses that you use and implement onSearchRequest, as in the example above, using an external search handler
source share