Gonzalo Huerta-Canepa • over 10 years ago
SmartService
In my application I do not want to listen for weather changes in an activity but in a service.
You have the SmartService class, but that class does not implement the smartWeatherChange event.
How can I achieve what I want? I guess that is using the LocalEvent manager, but I do not know which event should I register to
Comments are closed.

1 comment
trnql Manager • over 10 years ago
Hi Gonzalo
That's a great question. We can provide the ability to respond to these signals (activity, weather, location) in Android services in the future. For now, this is the code you need:
public void onCreate(){
super.onCreate();
addResource(new ObservablePropertyListener(R.id.op_SmartWeather_CurLoc_Weather,
"SmartActivity - smart weather OP listener ") {
@Override
public void onChange(int propertyId, Object value) {
if (value != null) {
_smartWeatherChange((WeatherEntry) value);
}
}
});
}
And then you have to implement the _smartWeatherChange(WeatherEntry value){} method in your SmartService subclass.
So you're just using an ObservableProperty called R.id.op_SmartWeather_CurLoc_Weather to get this data into your service (this is what SmartActivity does under the covers).
Thanks
trnql team