I'm trying to figure out the pros and cons of writing an android remote service as a part of my client app (using android:process=":remote") vs making it a separate service app.
In both the cases, the service would be running in its own separate process and having its own heap etc. However, there have to be some differences when we make it a separate app since it will have its own application sandbox. I found many examples of their usage and preferred approaches as per the scenarios but I'm trying to understand the internal technical details of it.
Any good source of information on this?
Edit: What will be the impact on the application object/context in case the service and client processes are running in the same app. Will it get overwritten by one of the processes? or there will be two application objects for each process which doesn't sound correct being the part of one app.
The difference between remote service and local service is: Local service runs in the same process and remote service runs in different process and may be in different application.
If the name assigned to this attribute begins with a colon (':'), the service will run in its own separate process. If the process name begins with a lowercase character, the service will run in a global process of that name, provided that it has permission to do so.
stopSelf() is used to always stop the current service. stopSelf(int startId) is also used to stop the current service, but only if startId was the ID specified the last time the service was started. stopService(Intent service) is used to stop services, but from outside the service to be stopped.
A service is started when an application component, such as an activity, starts it by calling startService(). Once started, a service can run in the background indefinitely, even if the component that started it is destroyed. A service is bound when an application component binds to it by calling bindService().
Your question has been partially answered before. Check here:
But if you still think about the idea of having something running on background, you can have a look in this reference:
Having things running on background is clearly not a good option. Unless you for any reason really need it. So, take care to not annoy the user with unnecessary background services that was not consciously activated by the user´s own will. In such case, making a separate App, or kind of a feature that will bee activated by the user is a smarter and safer road to take.
If you need to be able to write a Service that can perform complicated communication with clients in remote processes (beyond simply the use of Context.startService to send commands to it), then you can use the Messenger class instead of writing full AIDL files. If you only need a remote service, you should follow this tutorial.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With