Question

I have a mix-case IDL service that I'm using in 2 ways:

  1. The service will spawn a thread and make a network call to grab some XML content on Activity's behalf. The content is return back to the Activity through client's IDL that defines callback methods
  2. If user chooses notification option then service creates a Timer that gets executed repeatedly and creates a toolbar notification. It also cached the content so when Activity request an update it is served from the cache rather than another network call

So my questions are

  1. For scenario #1 what is the price (if any) I'm paying for using service for network calls instead of creating background thread directly in the Activity?
  2. For #2 - am I better off changing implementation to AlarmManager? I noticed that when I kill processes with TasKiller my service dies and never gets restarted, would AlarmManager-base job have better chance of recovery?
Was it helpful?

Solution

For scenario #1 what is the price (if any) I'm paying for using service for network calls instead of creating background thread directly in the Activity?

I am assuming that, since you said this is an "IDL service", that this is what I call a remote service -- you are using AIDL to define an interface that is being used across process boundaries.

In that case, the cost is several MB of RAM for the second process, plus a bit of CPU time for the IPC overhead. How much that "bit of CPU time" is depends on how frequently it is called.

For #2 - am I better off changing implementation to AlarmManager?

Generally, yes. Ideally, services are in memory as little as possible.

I noticed that when I kill processes with TasKiller my service dies and never gets restarted, would AlarmManager-base job have better chance of recovery?

No, because "task killer" apps tend to abuse an API (in Dianne Hackborn's words) that will kill off everything, including scheduled alarms. At present, there is no reliable & efficient defense against "task killers" that I am aware of.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top