I'm developing a motion detection app. This app uses the camera to compare continuosly taken frames to detect movement. So, I need the app to stay working and not being paused or stoped. I'm using WakeLock to achieve this, but I'm seeing in the android doc, that most methods are deprecated.

I don't care if the screen goes off, but the app must keep working. Now I'm using this:

mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "APP");

But the app stops when the screen goes off. I've seen that maybe this one fits better my porpouse: SCREEN_DIM_WAKE_LOCK but was deprecated in API level 17...

So, what would be the best way to get this?

有帮助吗?

解决方案

Best solution is to keep screen on.

Add android:keepScreenOn="true" in your layout XML resource for this activity. So long as that widget is visible on the screen, the screen will not turn off automatically.

Also use the permission:

<uses-permission android:name="android.permission.WAKE_LOCK" />
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top