App seems to stop working when the screen goes to sleep

后端 未结 3 2062
离开以前
离开以前 2020-12-05 15:59

I have a CPU intensive long-running operation (a few hours) that I am using AsyncTask to perform. As it continues, it updates a progressbar on the screen to show what percen

3条回答
  •  不思量自难忘°
    2020-12-05 16:43

    That's expected behavior. The idea is that the phone's battery is not supposed to drain because of bad apps. If the screen is off, the user generally expects the phone to sleep.

    If you need your app to run, you can use a WakeLock to keep the phone running (with the screen off): Documentation here and here.

    Note that a wake lock requires the WAKE_LOCK permission, and again, you need to make it clear to the user that your app will drink the phone's milkshake while it's off.

提交回复
热议问题