Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8260247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:03:33+00:00 2026-06-08T03:03:33+00:00

In my application throughout I want the search button to perform a separate Activity

  • 0

In my application throughout I want the search button to perform a separate Activity. i.e. From anywhere in the app when I press the search button I want a separate Activity to get called.

Is there any way that instead of defining onSearchRequested() in every activity, I just configure it at one place (like Manifest.xml) and it can be used throughout the app?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:03:34+00:00Added an answer on June 8, 2026 at 3:03 am

    You could define an (not necessarily) abstract class that extends Activity, implement onSearchRequest there and inherit all other Activity classes from that class. In this way you only have to define the onSearch behaviour only once.

    i.e.

    public abstract class MyBaseActivity extends Activity {
        @Override
        public void onSearchRequest() {
           // Your stuff here
        }
    }
    
    public class MyActivity1 extends MyBaseActivity {
       // OnSearchRequest is already implemented
    }
    

    If you plan to use multiple subclasses of Activity, i.e. ListActivity, this might not be a good solution, as you have to create a abstract base class for all Activity subclasses you use. In this case I’d recommend creating an additional class, encapsulating the search button handling code and call that from you activities onSearchRequest, i.e.

    public class SearchButtonHandle {
        public void handleSearch(Context c) {
           // Your search btn handling code goes here
        }  
    }
    
    public class MyActivity1 extends Activity {  // Or ListActivity ....
        @Override
        public void onSearchRequest() {
           new SearchButtonHandle().handleSearch(this);
        }
    }
    

    Of course you can also combine both approches by defining an Abstract Subclass of all Activity Subclasses you use and implement the onSearchRequest as in the example above with an external Search Handler

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to format my numbers throughout the application in a consistent way, no
UPDATE As I've tried to get MEF working throughout my application, I'm coming across
I am looking to replace the back button in the UINavigationController throughout my application.
I want to have only 5 instance of a class throughout the application life
If I want to log all occurrences of exceptions throughout my application so far,
I want to create a global function to use throughout my application. Let say
Are there any disadvantages of using jQuery's 'live' consistently throughout my application? If i
I use std::tr1::shared_ptr extensively throughout my application. This includes passing objects in as function
I have been tasked with testing the contents of several pop-ups throughout our application.
I have a static instance variable that is being used throughout my application. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.