A method for waiting for sensor data

前端 未结 2 1730
不思量自难忘°
不思量自难忘° 2021-01-14 23:00

I have a class which initiates a sensor listener when it is started. This listener writes the latest sensor value to a variable when an event is triggered. The class goes on

2条回答
  •  情话喂你
    2021-01-14 23:17

    This is not strictly related to android, but also general java question. Mechanism to implement this is container in java.lang.Oject. Assuming you have some guard object, where producer and consumer threads have access. On consumer thread you call:

    guard.wait(some_optional_delay_Look_into_javadoc);
    

    Then cosumer thread will wait until timeout ocurs or hell frozes out or producer thread issues:

    guard.notify[All]();
    

    (read documentation)

    Your service listener will be producer.

提交回复
热议问题