Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
300 views
in Technique[技术] by (71.8m points)

android - What are the Advantages and Disadvantages of running a service in different 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">

Question::

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...