当onSensorChanged()的调用之前就可以完成当前的执行会发生什么? [英] What happens when onSensorChanged() in called before it can finish the current execution?

查看:653
本文介绍了当onSensorChanged()的调用之前就可以完成当前的执行会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的职责。

 public void onSensorChanged(SensorEvent event)
    {

            if (event.sensor.getType() == Sensor.TYPE_LINEAR_ACCELERATION)
            {
               //DO A JOB...
            }
     }      

我的问题是会发生什么,如果 onSensorChanged()而这是完成当前的工作是叫什么名字?

My question is what happens if onSensorChanged() is called while it is finishing the current job?

推荐答案

如果同时previous样品上正在然后onSensorChanged将在两个样品进行工作的工作onSensorChanged被再次调用一次这可能是任何一个问题与计算的最终结果发生。我相信,这只是一个线程提供传感器事件然而所以真的不应该再次获得,直到处理这一个做调用。

If onSensorChanged gets called again while the previous sample is being worked on then onSensorChanged will be working on two samples at once which may be a problem for whatever is happening with the end result of the calculation. I believe that it is just one thread delivering the sensor event however so really it shouldn't get called again until the processing is done with this one.

在一般实践的研究虽然所有的处理应在另一个线程来完成,并onSensorChanged应尽快以便其他接收机能够对数据起作用,以及返回。还复制数据,不通过参考传感器数据,因为SensorData对象可能被重新使用,如果你保持围绕数据的引用可以由时间而改变你去使用它。

In general practive though all processing should be done in another thread and onSensorChanged should return as quickly as possible so other receivers can act on the data as well. Also copy the data, don't pass the reference to the sensor data since the SensorData object may be re-used and if you keep a reference around the data may change by the time you go to use it.

这篇关于当onSensorChanged()的调用之前就可以完成当前的执行会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆