Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure out some magical way to prevent the SensorManager from polling the accelerometer while the phone is locked #3

Open
SyntaxBlitz opened this issue Nov 17, 2014 · 3 comments

Comments

@SyntaxBlitz
Copy link
Owner

No description provided.

@kuleszdl
Copy link
Contributor

Okay, but normally when you open a whole application which uses the sensor and close it the sensor is not used anymore, right? Did you try to maybe fork a new thread/process which does the polling and kill/spawn it as required? Maybe this way you could overcome the non-working SensorManager?

@SyntaxBlitz
Copy link
Owner Author

I did consider this but never actually tried writing it. I don't think I know enough about Android's process management, nevermind inter-process communication, to successfully write that code.

Already, the polling code is inside a Service. When I get the phone lock event, I kill the entire Service, which is supposed to kill the SensorManager in its onDestroy method (this is the bit that doesn't work). Even though the Service is dead, I still get values from the sensor.

When the Service is not running, the application is doing nothing (assuming the settings Activity is not open). It has registered its BroadcastReceiver for the lock/unlock events, and then it is totally passive. Spawning another process and controlling that one would probably work, I agree. But it seems silly that, given that I'm killing the Service when it's not in use, that's not already what's happening. I also worry, in spawning another process, about the processes running out of sync. The worker process might be killed prematurely, and it might also take extra time to start up once the main app gets the unlock event. Most of the code would actually be inside this worker process, so it just seems weird that I'd even need two processes in the first place.

This issue definitely frustrates me. If I get time, I'll look at how I can spawn a new process. I'd just have to hope that that works.

@SyntaxBlitz
Copy link
Owner Author

Here I'll leave the link to the StackOverflow question I've posted.

I did mention in the last paragraph that I was looking for alternative methods, like those involving process management. I don't know quite how successful I'll be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants