Android Question Backgroundworker in separate process

beachner

Member
Is it possible to add the android:process tag to a service element in the manifest? I need to run the background service in a separate process so I can use the Android Webview without the background service being killed when the webview gets updated.
 

OliverA

Expert
Licensed User
Longtime User
Never mind, found the answer. You of course use SetServiceAttribute in the manifest editor
I need to run the background service in a separate process
Could you elaborate more on your solution? Services do not run on a separate thread/process, nor does SetServiceAttribute give the service such capabilities. So did you create a separate thread/process for your service or did the correct setting of the SetServiceAttribute do the trick (and if so, what was your setting)? Any information you give here would help future searchers look at an actual solution instead of just a "I did it" without any other context.
 
Upvote 0

beachner

Member
Could you elaborate more on your solution? Services do not run on a separate thread/process, nor does SetServiceAttribute give the service such capabilities. So did you create a separate thread/process for your service or did the correct setting of the SetServiceAttribute do the trick (and if so, what was your setting)? Any information you give here would help future searchers look at an actual solution instead of just a "I did it" without any other context.
Sure.
According to the Android documentation

If we want to make this service run in a remote process (instead of the standard one for its .apk), we can use android: process (remove the space) in its manifest tag to specify one
For example:
<service android:name=".app.MessengerService"
android:process=":remote" />
By using

B4X:
SetServiceAttribute(backgroundworker,android:process,:background)

I was able to get that attribute on the the Manifest element. That being said, I'm not sure the background service is actually being started. I need to check the device logs with Android Studio to see if the service is being started. Can't see anything in B4A.
 
Upvote 0

beachner

Member
Never mind, found the answer. You of course use SetServiceAttribute in the manifest editor
With this I was able to get the android: process on the service element in the manifest but the service doesn't appears to start with this attribute on. Why I don't know. For now I might abandon this idea.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
manifest but the service doesn't appears to start with this attribute o
Could it be that you need to quote the 3rd entry?
B4X:
SetServiceAttribute(backgroundworker,android:process,":background")
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
There may be a caveat with this if you do get it to work. According to a stockoverflow.com answer, this will cause another Application instance to be started. I wonder how this will work with a B4A application. Would it fire up the Starter service again? A B4XPages application, how will it handle such a start?

Link: https://stackoverflow.com/a/30330398
 
Upvote 0

beachner

Member
Could it be that you need to quote the 3rd entry?
B4X:
SetServiceAttribute(backgroundworker,android:process,":background")
Yes, you're correct. With that little addition the service is running. Don't know how I missed that 🤦‍♂️

There may be a caveat with this if you do get it to work. According to a stockoverflow.com answer, this will cause another Application instance to be started. I wonder how this will work with a B4A application. Would it fire up the Starter service again? A B4XPages application, how will it handle such a start?

Good question, I will have to experiment and see but a quick test before writing this post seems promising
 
Upvote 0
Top