Skip to content

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

Open

Description

@SyntaxBlitz
No description provided.

Activity

  1. kuleszdl commented on Jan 22, 2015

    @kuleszdl
    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?

  2. SyntaxBlitz commented on Jan 22, 2015

    @SyntaxBlitz
    OwnerAuthor

    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.

  3. SyntaxBlitz commented on Jan 22, 2015

    @SyntaxBlitz
    OwnerAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions