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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:25:38+00:00 2026-05-25T01:25:38+00:00

i make an emergency application that will send a SMS to the 5 people

  • 0

i make an emergency application that will send a SMS to the 5 people when volume down key or menu key is pressed.
this is my code for detect a keypress when the activity launched:

package com.application.tpa;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.Toast;

public class main extends Activity {
    /** Called when the activity is first created. */
    int ctrMenu=0,ctrkeyUp=0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //startService(new Intent(main.this, PAservice.class));
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_MENU)) {
            ctrkeyUp=0;
            ctrMenu++;
            if (ctrMenu==5)
            {
                Toast.makeText(this, "You pressed the Menu button!", Toast.LENGTH_LONG).show();
                ctrMenu=0;
            }
            //return true;
        }
        else if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
            ctrMenu=0;
            ctrkeyUp++;
            if (ctrkeyUp==5)
            {
                Toast.makeText(this, "You pressed the Volume Down button!", Toast.LENGTH_LONG).show();                     
                ctrkeyUp=0;
            }
            //return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}

has everyone know how to create timer (or whatever) in android to reset my counter variable into zero every 3 second?? so i can runs some procedure when a button is pressed 5 times before 3 seconds.. Thanks..

  • 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-25T01:25:39+00:00Added an answer on May 25, 2026 at 1:25 am

    This is how you can use the Timer using TimerTask:

     Timer timer = new Timer();
    
            timer.schedule(new TimerTask() {
                public void run() {
    
                   // add your stuff here
                    }
                }
            }, 3000, 3000);
    

    To cancel the timer you can use timer.cancel();

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

Sidebar

Related Questions

I make a distributed embedded application that will make use of several micro-controllers. The
I make an iframe application for a fan page, the problem is that if
I make this call in my application.js file but it doesn't seem to return
(Make this CW if needed) We are two developers working on a web application
Make sure you run outside of the IDE. That is key. -edit- I LOVE
I make a call just like this: value = ./simulated_annealing Which is a C
Can I make an emergency call programmatically in Android 2.1? I've tried to use
How can I do this with the JS replace() method: Make \n\n change to
I make some script, that have modal window on fancybox and on load it's
Make javaScript and CSS External Source . Does that mean I should use JavaScript

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.