I want to run a long running Service in the background in my App.so i am using Service for that but in the service there is tag called android:process
So my service is like..
<service
android:name="com.purpleshade.services.ApplicationService"
android:process=":myprocess">
Question::
So i want to know about the Advantages and disadvantages of running a Service
in different Process.
Off the top of my head...
Downsides:
- You have to use interprocess communication to talk to it, which is slower than if it were in the same process as the client.
- Debugging becomes more difficult, as now there is a different process you potentially need to attach to.
- If it crashes, it crashes independently of your main process. One might argue this is an upside too though. Something to consider.
- Special care is needed in any initialization code, such as in your Application instance. There will be an instance of the Application context for each process. So, for example, if you are initializing something like GCM, you probably want to make sure only doing so in the main process. (Referring to this, specifically: http://developer.android.com/reference/android/app/Application.html)
Upside:
- The only real upside I can think of, and really the only time I've used a separate process, is that you get a whole new heap space to work with independent of the main process. Useful if you need this memory for some operation.
Con : Using android:process=":myprocess"
is really bad if you want to update values or communicate with the app, none of your values will get updated.
Be careful while using it. (It took me a 2 days to figure out)
Pro : Doesn't block the app while running long process.