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 8931639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:09:27+00:00 2026-06-15T09:09:27+00:00

I have many Activity which need to override onKeyDown event as below: @Override public

  • 0

I have many Activity which need to override onKeyDown event as below:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // Do something here
        return false;
    }
    return super.onKeyDown(keyCode, event);
}

The problem here is that: I have many activities that should call the block of code above (no different in any activity). So I want to write an helper’s function like:

 public static void overrideOnKeyDownFunction(...);

And, in any activity that need to override onKeyDown event (same with first code block), I can only call: Helper.overrideOnKeyDownFunction(...);!

Can I do some thing like this? And how to do it? Thanks in advance!

  • 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-15T09:09:28+00:00Added an answer on June 15, 2026 at 9:09 am

    I think the best way of sharing that behavior between different activities is making all of them inherit from the same superclass that overrides the onKeyDown method.

    So, if you create an Activity with onKeyDown overriden (let’s say OverridenBackKeyActivity) any Activity inheriting from OverridenBackKeyActivity will automatically inherit that behavior.

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

Sidebar

Related Questions

I have many PowerPoint presentations that I need to be able to add to
I have an application that depends on connection It has many Activities.I need to
i have design an application where it have many activities and one activity is
Throughout our enterprise we have many applications that log activity to text files for
I have an app that goes between many different activities. One activity, my main
I have an activity which has some text views and other data to be
Hi I have an application which after login, loads a main activity which contains
I have a ListView on main activity, which shows a Contact picture on the
I have created a Project having many activities. One activity is to record the
Ok I have seen many posts on this script. Which can be found..... http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/

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.