How to Keep the CPU of android phone always awake?

前端 未结 1 1436
梦谈多话
梦谈多话 2021-01-21 20:12

I have been stuck on it for days. I need to execute a function every minute. This function is making a POST call from the App to the Server and is transferring the location of t

1条回答
  •  温柔的废话
    2021-01-21 20:55

    First of all, your SimpleWakefulService does not look very wakefull, it should aqurie WakeLock but it doesnt. For example of such service look here:

    https://github.com/commonsguy/cwac-wakeful/blob/master/wakeful/src/com/commonsware/cwac/wakeful/WakefulIntentService.java

    Next thing, is update function. It is called in the context where PARTIAL_WAKE_LOCK is aquired, but the thread within it is executed asynchronously, that means also after wakelock is released. And that is whats causing problems.

    Solution is to move your thread code from update function (thread is not needed) to WakefulIntentService as in above link.

    0 讨论(0)
提交回复
热议问题