I'm kind of new to java and in my test project I encountered a problem.
How can I return value from a void method? If I change the title, I receive this error :
"attempting to use incompatible return type" here is the code
public void show_sensor (Context appcontext, int sensortype){
new ReactiveSensors(appcontext).observeSensor(sensortype)
.subscribeOn(Schedulers.computation())
.filter(ReactiveSensorFilter.filterSensorChanged())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<ReactiveSensorEvent>() {
@Override
public void call(ReactiveSensorEvent reactiveSensorEvent) {
SensorEvent event = reactiveSensorEvent.getSensorEvent();
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
String message = String.format("x = %f, y = %f, z = %f", x, y, z);
Log.d("gyroscope readings", message);
}
});
}
I want to return "message" is there any way i can do this?
And I also have a problem getting application context, so I had to pass it on, is it possible to get ApplicationContext from within the class so I can run it in the background?
(i want to set up a broadcast and i cant use "getApplicationContext()" in the receiver class)