Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android remote service within the app vs separate app

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.

like image 590
pree Avatar asked Jan 16 '14 23:01

pree


People also ask

What is local and remote service in Android?

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.

Is service a separate process in Android?

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.

How do I stop programmatically running in the background Android?

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.

What is the correct way to start s service in Android?

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().


1 Answers

Your question has been partially answered before. Check here:

  • using android:process=":remote" recreates android Application object

But if you still think about the idea of having something running on background, you can have a look in this reference:

  • Developing an App with a Background Service

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.

like image 119
Avanz Avatar answered Oct 10 '22 11:10

Avanz