Android Question Get value of stepcounter sensor at application start

06Pierrick06

Member
Licensed User
Hi there,

I would like to get the value of "step counter" Sensor as of "Activity_Create" event.

Currently this step counter value is stored in a Global variable "VG_COMPTEUR_GEN" set in "Sensor_SensorChanged" Sub

It works but I have to walk 10 steps for this Sub to execute while I need the value just after my application starts and even if I'm static.

Any way to do this please ?


B4X:
Sub Sensor_SensorChanged (Values() As Float)

    Dim ps As PhoneSensors
    Dim sd As SensorData
    Dim lbl As Label

    'Get the PhoneSensors object that raised this event.
    ps = Sender   
    sd = SensorsMap.Get(ps) 'Get the associated SensorData object    
    lbl = SensorsLabels.Get(ps) 'Get the associated Label.

    VG_COMPTEUR_GEN = Values(0)    

End Sub
 

emexes

Expert
Licensed User
step counter value is stored in a Global variable "VG_COMPTEUR_GEN"

You should be able to access the value of a (Public) Global variable from other modules by referring to it as module.VG_COMPTEUR_GEN where module is the name of the other file where the variable is declared.
 
Upvote 0

06Pierrick06

Member
Licensed User
Many thanks for your prompt reply.

I was trapped by the start order of Activity_create then Activity_resume so my Global variable was not yet fed by a value. I had to move my code in right place.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…