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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:23:50+00:00 2026-05-28T13:23:50+00:00

I am having 10 different buttons in my application for different task to perform.

  • 0

I am having 10 different buttons in my application for different task to perform. I want to develop one service which continuously check (listens) and if user is not clicking any button for particular time let say for 5sec than i wish to perform some other task. How can I check that user has not clicked any button? If anyone having any idea please kindly let me know.

  • 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-28T13:23:51+00:00Added an answer on May 28, 2026 at 1:23 pm

    In each of your click listeners save off the time the last button was clicked:

    private long lastClickTimestamp;
    private Handler handler = new Handler();
    
    public void onCreate( Bundle saved ) {
       BackgroundJob job = new BackgroundJob();
       handler.postDelayed( job, SECONDS_TO_WAIT * 1000 );
    
       button1.setClickListener( new OnClickListener() {
           public void onClick( View view ) {
               lastClickTimestamp = System.currentTimeInMillis();
               // do the listener logic for button 1 here.
           }
       });
    
       button2.setClickListner( new OnClickListener() {
           public void onClick( View view ) {
               lastClickTimestamp = System.currentTimeInMillis();
               // do the listener logic for button 2 here.
           }
       });
    
       // repeat that for all 10 buttons.
    }
    

    Now the smarter developer would create a reusable base class that handled setting the timestamp once, then reuse that base class in each of the 10 buttons. But, that’s left up to you. Then the background job would look like:

    public class BackgroundJob implements Runnable {
    
       private boolean done = false;
    
      // meanwhile in job:
      public void run() {
    
         if( lastClickTimestamp > 0 && System.currentTimeInMillis() - lastClickTimestamp > SECONDS_TO_WAIT * 1000 ) {
           // let's do that job!
         }
    
         if( !done ) {
            // reschedule us to continue working
            handler.postDelayed( this, SECONDS_TO_WAIT * 1000 ); 
         }
      }
    }
    

    If you have to use a service you can send a notification to the service saying a button was clicked, then the service can keep track of the time when that occurred. I wouldn’t use a service for this because playing an animation or sound doesn’t need to survive if the app is put into the background or killed. Services are meant for things like playing music when someone is doing something else, chat applications, or things that need to run in the background when the user isn’t interacting with the application. What you’re describing could be done as I’ve shown because when the user gets a phone call or text message they’ll leave your application, and the animation or sound you’re playing probably should stop too. Pretty easy to do with the Handler option I showed. More difficult, but doable, with a service.

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

Sidebar

Related Questions

The android application having a toolbar with three buttons of three different implementations. The
In our e-commerce application, we have different kinds of products having different kinds of
My application supports both Oracle and MS SQL databases, with slightly different schemas having
I am building a Rails application which allows a user to create an object
In android generally for buttons having different background are stored in a xml file
I'm having an application with different views, and when I'm flinging at right or
I'm having problems with my application receiving low memory warnings while the user is
I have some forms in my application which have different states depending on what
Scenario: I have a WPF desktop application which will be distributed on different machines
I am trying to understand if having different number of columns for different rows

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.