Question

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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top