What are the Advantages and Disadvantages of running a service in different process?

不打扰是莪最后的温柔 提交于 2019-12-17 18:43:29

问题


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.


回答1:


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.



回答2:


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.



来源:https://stackoverflow.com/questions/20657192/what-are-the-advantages-and-disadvantages-of-running-a-service-in-different-proc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!