small medium large xlarge

05 Nov 2012, 11:40
Olaf Heddergott (11 posts)

I have compiled and installed MultipleSensors.pde on my samsung galaxy SIII. If I run the app once and leave it with the back button, it is permanently showing in the power overview. It looks like the app is continuously using the cpu. why? tested on android 4.0.4 and 4.1.1

08 Nov 2012, 17:36
Daniel Sauter (54 posts)

Hi Olaf,

you need to call the KetaiSensor stop() method to pause the sensors. This gives you the control to start and stop capturing sensor data when your app requires it, and not via the Android life cycle onPause(). Some applications require to keep capturing sensor data in the background, so it’s important to allow for it.

Best, Daniel

13 Nov 2012, 08:36
Olaf Heddergott (11 posts)

I extended the source code with the exit function like shown below.

With ketai v7 and v8 and MultipleSensors.pde (with exit function) I call stop with no luck.

I start the MultipleSensors on phone, close it and load the mobile to 100%. then disconnect the power supply and looking in the accu usage and see MultipleSensors is running without end. the only way to stop is deinstallation.

I write a little sample for the light sensor (at this time I only need this sensor) and test it with ketai v8. this is not running in background.

here my sample:

import ketai.sensors.*;

KetaiSensor sensor; float light;

void setup() { size(720, 1280); orientation(PORTRAIT); textAlign(CENTER, CENTER); textSize(40); sensor = new KetaiSensor(this); sensor.start(); }

void draw() { background(0,100,0); textAlign(CENTER); fill(255); text(“Licht: “ + light, 20, 0, width, height); }

void onLightEvent(float v) { light = v; }

void exit() { if (sensor.isStarted()) sensor.stop(); println(“the end”); super.exit(); }

can the problem be in usage other sensors as the light sensor? I test the sensor.stop in many ways but the result is the same. Must I stop the accelerometer and the other sensors separately?

17 Dec 2012, 07:53
Daniel Sauter (54 posts)

Dear Olaf,

the KetaiSensor stop() method works as exhibited in the MultipleSensors Example of Chapter 3.6

“Kill” an activity is handled by the Android system, and apps that try to kill themselves (onPause() or exit() or finish()) will be restarted and paused back of the application stack.

calling sensor.start() in setup() will also re-activate your sensors.

Best, Daniel

You must be logged in to comment