0

I have implemented Shake Event listener in my application and onShake do some logic. I want to show a dialog after the user has stopped shaking the phone. Where do I need to implement this logic? If I do it onShake itself then multiple dialogs will appear. Can someone help me?

Thanks Jai

Th0rndike
  • 3,360
  • 3
  • 19
  • 39
jai
  • 93
  • 8
  • can we see your shake event listener? it is possible that you need to set an interval between shakes to avoid the event firing repeatedly – Th0rndike Apr 04 '12 at 12:23
  • I have actually implemented the one suggested by another user http://stackoverflow.com/a/5117254/1068513 – jai Apr 04 '12 at 12:41
  • which one? the one accepted as solution? every listener in that question has a different approach. If it's the one accepted on the answer, it doesn't handle the time between shakes, so you need to implement it. – Th0rndike Apr 04 '12 at 12:48
  • Not the accepted one but the one below that. The link above will take you directly to the one I implemented. – jai Apr 04 '12 at 13:41

1 Answers1

0

so, thinking about your problem, i was initially considering to "tweak" the constant values of your listener (MIN_FORCE, MIN_TIME... etc) in order to create some "resistance" for the event, so it wouldn't be fired excessively. Then i realized it was a stupid idea, since there is a much better solution... just unbind the event handler when the shake event occurs, and then re-bind it when the user dismisses the dialog. To do this, use the same code provided in the answer you used for the onResume and onPause methods:

this to bind the listener:

    mSensorManager.registerListener(mSensorListener,
    mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
    SensorManager.SENSOR_DELAY_UI);

and this to unbind it:

mSensorManager.unregisterListener(mSensorListener);
Th0rndike
  • 3,360
  • 3
  • 19
  • 39