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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:38:38+00:00 2026-05-31T00:38:38+00:00

I am new to Android development and at the moment I must make a

  • 0

I am new to Android development and at the moment I must make a decision of where to control the gesture input, but I just don’t know the pros and cons of where to grab the touch input. I have been given two alternatives, can you please explain to me the pros and cons of either way?

Set listener on View; implement methods:

faceView.setOnTouchListener(new OnTouchListener(){
   public boolean onTouch(View arg0, MotionEvent arg1){
     return false;
   }
);

or

Override method within View

public boolean onTouchEvent(MotionEvent event){
   return false;
}
  • 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-05-31T00:38:39+00:00Added an answer on May 31, 2026 at 12:38 am

    APPROACH 1: Anonymous Inner Type.

    faceView.setOnTouchListener(new OnTouchListener(){
       public boolean onTouch(View arg0, MotionEvent arg1){
         return false;
       } 
    );
    

    This is Anonymous, because it is a declaration without a name. There is no OnTouchListener mytouch =, there is only the declaration new OnTouchListener(). This is inner, because it is inside another class, and it is a type because it is an implementation of an interface.

    OK, so with that in mind. This approach is more convenient for developers. Functionality is isolated (generally by the declaration of the listenerable) and this is easily managed. But this convenience comes with a cost. Assume you have buttons, with ten onClickListeners. With this approach, the garbage collection queue will fill up faster with each new anonymous inner type.

    But does it matter? Not really. If you are trying to get every microsecond of performance out of your system, then sure don’t use this approach. But generally, this is viable.

    APPROACH 2: Single Inheritance

    public boolean onTouchEvent(MotionEvent event){
       return false;
    } 
    

    Assuming you read the above, this approach has a much lower cost for creation and cleanup. There is only 1 extra class instantiated, and only 1 object added to the GC queue.

    This is the approach I use, and have used for a while. It’s also what I see in Google’s sample source code.

    But it’s not perfect! The implementation of onTouchEvent will end up looking as such:

    public void onTouch(Event e){
    if (e.equals(View1)){
    }else if (e.equals(View2)){
    }else if (e.equals(View 3)){
    ...}
    

    SO

    Honestly, it doesn’t matter. If you want the highest performance possible, use a static onTouchEvent listener, and you won’t have to pay the above mentioned costs, but for the most part they are not that expensive anyways.

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

Sidebar

Related Questions

I'm new to android development and I've developed a small app but I'm facing
I'm pretty new to android development, so I hope my question is easy, but
I'm very new to Android development and just started to study. What I'm trying
I am new to android development but in the past few weeks I have
I'm new to android development and I'm trying to make an android app that
I am new to android development, but I am trying to add admob to
I just started a new Android project, WeekendStudy to continue learning Android development and
Im new to android development. I would like to know why do we have
I am new to android development My eclipse was working properly. But now when
I'm new to Android development, and I was wondering if anyone knew either how

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.