On Sun, Mar 29, 2009 at 5:58 PM, gjs <[email protected]> wrote:
> (1) Is it recommended that a Service which runs for more than a few > seconds always use a wake lock in an attempt to ensure it completes ? It's not really a matter of how long you run. If you want to run at all, and don't know that the screen will be on while doing do, then you need to hold a wake lock. > My limited tests on a G1 seem to show that a Service that runs for a > few minutes ( up to about 5 minutes ) does not seem to need a wake > lock as the phone stays awake at least until the service is completed. > I have not tried forcing the issue by turning the phone off during the > Service running. This is just happen-stance. There is no minimum amount of time that the system keeps the CPU running for your service to run; the CPU will only run while someone is holding a wake lock. > (2) Where a Service is killed by the system in a low memory situation > and possibly restarted, is the Services onDestroy() method always > called by the system or is the Service just killed ? No, nothing is called. You will usually get onLowMemory() though. > If the system then restarts the Service is onStart() called again with > any of the original pending Intents or is only onCreate() called and > the Service is then responsible for working out what work is still > outstanding based on what it has previously stored about those intents > from persistent storage ? Only onCreate() is guaranteed to be called. The onStart() method will only be called if there are outstanding startService() requests that you have not seen. > And do these behaviors vary according to whether the Service runs in > the same process as an Activity, or in its own separate process ? ( I > am mainly asking about a Service which runs in its own process ) The rules are outlined in the docs, and there is nothing special about having one thing run in one place or another... except whether the process will be killed is determined by the most import thing in that process. > (3) Should the threads running in a service always be niced down or > will the system eventually do this automatically ? You should do this. Use Process.setThreadPriority(); there is a standard constant for background threads. -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

