Reputation: 1
So I am trying to make an app that needs to use some networking stuff while running
in the background. (From a thread cause you can't otherwise and cause it's in the background)
But when I lock the device after a little while the thread just stops and the app is no longer running. I've been trying to figure out how to use wakelock to keep the device cpu running but I didn't manage to do that.
Even though I have the WAKE_LOCK permission in my manifest it tells me that:
java.lang.SecurityException: Neither user 10783 nor current process has android.permission.WAKE_LOCK.
Does anyone knows how to fix this or what is the proper way to do something like that?
Thanks in advance.
Upvotes: 0
Views: 706
Reputation: 93688
Well, to fix that problem you need the wakelock permission in your manifest. But its only going to be your first problem. Android is really meant to discourage background work when your app is not on screen, for battery optimization reasons. Just having a thread is not going to cut it- your app will be killed shortly after being backgrounded for resources.
If you need to do occassional background processing, look into WorkManager. It allows your app to be schedules for background work for brief periods.
Upvotes: 0