在不同的流程中运行服务的优缺点是什么? [英] What are the Advantages and Disadvantages of running a service in different process?

查看:89
本文介绍了在不同的流程中运行服务的优缺点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的App中在后台运行长期运行的服务.所以我正在为此使用Service,但是在服务中有一个名为android:process的标记,所以我的服务就像..

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">

问题::

所以我想知道在不同的流程中运行Service的优点和缺点.

So i want to know about the Advantages and disadvantages of running a Service in different Process.

推荐答案

离我远去...

缺点:

  • 您必须使用进程间通信与之对话,这比与客户端处于同一进程中的通信要慢.
  • 调试变得更加困难,因为现在您可能需要附加一个不同的过程.
  • 如果崩溃,它将独立于您的主进程而崩溃.也许有人会认为这也是一个好处.需要考虑的事情.
  • 在任何初始化代码中,例如在您的Application实例中,都需要特别注意.每个过程都会有一个Application上下文实例.因此,例如,如果要初始化类似GCM的内容,则可能要确保仅在主过程中这样做. (请参阅此内容,具体是: http://developer.android.com/reference/android/app/Application.html )
  • 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)

上方:

  • 我能想到的唯一真正的优势,也是我唯一使用单独的进程的唯一机会,是您获得了一个全新的堆空间来独立于主进程使用.如果您需要此内存用于某些操作,则很有用.

这篇关于在不同的流程中运行服务的优缺点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆