• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Interrupting A Vibration Pattern And Starting A New One Without Issues

Jack Dev

Lurker
Hello, I am starting a vibration pattern using:

v.vibrate(pattern, -1);

It works without problems. Though, I want to allow the user to interrupt it and start a new pattern. I have tried cancelling the vibration:

v.cancel();

Though, when I start the new pattern after cancelling. It does not work properly. It is as if there is a residual vibration from the first pattern placed on the second pattern. So, I guess I need to find a way to fully reset the vibration after cancelling. I have tried the documentation without luck. I have tried placing the vib code inside a new thread then interrupting the thread. That did not work. I have even thought of turning the vibration settings on and off. That no longer works in new apis, sadly. I have ran out of ideas. Can someone point me in the right direction to interrupting the vibrator and starting fresh?

Thanks.
 
Last edited:
Please show the relevant parts of your code, formatted in [code][/code] tags.
 
Hello, LV426VIP and thanks for the reply. The code is really simple. I have a button with the following code:

Code:
virabtebtn.setOnClickListener(new OnClickListener() {
   Vibrator v = (Vibrator) getSystemService(getApplicationContext().VIBRATOR_SERVICE);
   v.cancel();
   v.vibrate(pattern, -1);
}

So, when the user pushes that button the pattern, it silences the last pattern and starts the new (in this case same) pattern. I even put:

Code:
   v.cancel();

In a different button click. In this approach the user would start the vibration pattern using the vibratebtn and cancel it using another button where v is defined as a global variable accessible to both buttons. If I can only start a new instance of the vibrator or totally kill it and start over that would be awesome. Though, I do not know how.
 
So a couple of questions:-

- What's the value of variable pattern?
- What exactly happens when you run the above code?
 
Back
Top Bottom