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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:51:12+00:00 2026-06-13T08:51:12+00:00

I declare my variable ‘shake’ as a global variable, then I created new object

  • 0

I declare my variable ‘shake’ as a global variable, then I created new object inside the oncreate, then I call this :

@Override
public void onPause() {
    super.onPause();
    shake.cancel();
}

my phone can still vibrate although home button is pressed! I tried onStop(), same doesn’t work..

my app is like this : countdown 10 sec, after that vibrate.. but the problem is onPause cannot be call so the user may feel where’s the vibrate come from if it’s set 2 minutes on the countdown ticker.. help!

  • 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-13T08:51:13+00:00Added an answer on June 13, 2026 at 8:51 am

    Since I can’t see the rest of your code, I’m gonna assume a few things.

    Assumption #1

    If you have your activity open, and the countdown starts and expires after 10 seconds, your phone vibrates (with your activity still open). If you go to home screen, the vibration stops.

    Assumption #2

    You have your activity open, and the countdown starts. Before the 10 second expires, you go to home screen. Your activity is not visible, but the phone starts vibrating soon.

    If this is what you are seeing, it’s the correct behavior. The problem is that in the 2nd case, your shake.cancel() from onPause() is called when you go to the home screen, before it actually starts vibrating. shake.cancel() can only cancel if it’s already vibrating.

    If that’s what you are trying to fix (I can only assume since I can’t see the rest of your code), you can try this:

    private boolean mAllowShake = false;
    @Override
    public void onResume() {
       super.onResume();
       mAllowShake = true;
    }
    
    @Override
    pulic void onPause() {
       super.onPause();
       mAllowShake = false;
       shake.cancel();
    }
    
    // wherever you are calling the shake.vibrate()
    if (mAllowShake)
       shake.vibrate();
    

    This way, when your activity is not visible and your timer goes off, since mAllowShake is false, it won’t actually vibrate.

    If that’s not what you are trying to fix, please update your question with more code and description of your exact use case. Hope it helps!

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

Sidebar

Related Questions

Possible Duplicate: Declaring a global variable inside a function Is it possible to declare
i declare a global variable and use and modify its value in the function.
When I declare a enum variable like this: enum paint_colors { RED, GREEN, BLUE,
Any way to declare a new variable in F# without assigning a value to
I need to declare 3d array variable but can't. int[][][] ary = new int[5][2][];
I'm trying to declare a global variable from within a class like so: class
i meet a code like this, it seem use declare -i to declare variable
If I declare a variable static and compiled this class into a executable jar.
If I declare a variable within a block (see below) is there a way
Let's say I declare a variable: String a = test; And I want to

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.