How to make a copy of the Android Sensor SensorEvent Object

喜夏-厌秋 提交于 2019-12-08 09:33:35

问题


I have a sparesArray which I use to store & batch SensorEvents by holding onto each sensor typeId and SensorEvent object until a timer fires.

  SparseArray<SensorEvent> sensorEventMap   = new SparseArray<SensorEvent>();

  public void onSensorChanged(SensorEvent event) {
    synchronized (this) {
        sensorEventMap.put(event.sensor.getType(), event);
    }
}

I am having issues where the SensorEvent is getting overwritten in the array before my timer fires, so I'd like to make a copy of the SensorEvent and store the copy in the array instead.

How can I make a copy of SensorEvent ?

I need the whole SensorEvent, not just the data values.


回答1:


Not possible as it is a system class you wont be able to make it implement the cloneable interface. Better to just create your own clone class and copy it yourself.



来源:https://stackoverflow.com/questions/13164107/how-to-make-a-copy-of-the-android-sensor-sensorevent-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!