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

Apps onSensorChange to only run once

Nismon8er

Lurker
Jun 19, 2017
1
0
Hello,

I have been searching everywhere but no luck...

I have something similar to a magic 8 ball app

Right now when i face the phone downwards it loads a picture from a site, but it runs about 10 times until i face the phone back up.... i have a simple if statement where if the Z value is less that -9.5 then run the code else dont do anything.... but since onSensorChange runs constantly due to gravity it runs over and over.... is there a way to make it run only once, then stop running until user place phone upwards again
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones