First, I have no desire to be evil. Yet I have an app that must listen for events, and it seems that the only way to hear those events is with a listener in a persistent service that starts up on device boot. The reason is that not all those events have a corresponding broadcast. There are also efficiency and UI issues in that data structures need to be rebuilt every time the service must start to deal with events. A particular example of interest to me is PhoneStateListener, and in particular incoming phone calls. I see no way around having a persistent service at this time, and in fact I need to take some special action to fairly quickly get the service going again should the system kill it. After all, the user downloaded the app and expects it to do what we say it does.
Is there a better approach that meets the requirement yet also plays well with resource contention? Will there at least be more broadcasts in future that will complement additional listener events? I know this is asking for a lot, so perhaps being evil for now is in fact the lesser evil. I really do want the app to cooperate with the Android environment. On Jul 23, 3:58 pm, Dianne Hackborn <hack...@android.com> wrote: > Mark answered how to do this, but please: think again about whether you > really need to do this. Then think another time. And think once more. And > if you are really really absolutely positively sure, this what you want to > do, fine, but realize -- > > On current Android devices, we can keep only a small handful of applications > running at the same time. Having your application do this is going to going > to take resources from other things that at any particular point in time > would be better used elsewhere. And in fact, you can be guaranteed that > your service will -not- stay running all of the time, because there is so > much other stuff that wants to run (other background services that are only > running when needed will be prioritized over yours), or needs more memory > for what the user is actually doing (running the web browser on complicated > web pages is a great way to kick background stuff out of memory). > > We have lots of facilities for implementing applications so they don't need > to do this, such as alarms, and various broadcasts from events going on in > the system. Please please please use them if at all possible. Having a > service run forever is pretty close to the side of evil. > > On Wed, Jul 22, 2009 at 5:43 PM, R Ravichandran > <ravirajami...@gmail.com>wrote: > > > > > Hello, > > > I have a need to create a background service that starts up during the > > system boot up, and keeps running until the device is powered down. There is > > no UI or Activity associated with this. I created a class extending the > > android Service class, and added the setttings to the AndroidManifest.xml > > file. When I launch this service in the emulator, I don't see this launched > > at all. I have overrided almost all the methods in the Service class to put > > log statements, but none of them shows up. > > > I believe the key is in the console message: > > > [2009-07-22 17:38:59 - MyEventsManager] No Launcher activity found! > > [2009-07-22 17:38:59 - MyEventsManager] The launch will only sync the > > application package on the device! > > > I am not sure what to make of this. > > > Here is the AndroidManifest.xml file: > > > <?xml version="1.0" encoding="utf-8"?> > > <manifest xmlns:android="http://schemas.android.com/apk/res/android" > > package="com.test" > > android:versionCode="1" > > android:versionName="1.0"> > > <application android:enabled="true" android:icon="@drawable/icon" > > android:label="@string/app_name"> > > > <service android:name=".MyEventsManager" > > > android:permission="android.permission.RECEIVE_BOOT_COMPLETED"> > > <intent-filter> > > <action android:name="android.intent.action.BOOT_COMPLETED" > > /> > > </intent-filter> > > </service> > > > </application> > > <uses-sdk android:minSdkVersion="3" /> > > </manifest> > > > Here is the console output: > > > [2009-07-22 17:38:59 - MyEventsManager] ------------------------------ > > [2009-07-22 17:38:59 - MyEventsManager] Android Launch! > > [2009-07-22 17:38:59 - MyEventsManager] adb is running normally. > > [2009-07-22 17:38:59 - MyEventsManager] No Launcher activity found! > > [2009-07-22 17:38:59 - MyEventsManager] The launch will only sync the > > application package on the device! > > [2009-07-22 17:38:59 - MyEventsManager] Performing sync > > [2009-07-22 17:39:01 - MyEventsManager] New emulator found: emulator-5554 > > [2009-07-22 17:39:01 - MyEventsManager] Waiting for HOME > > ('android.process.acore') to be launched... > > [2009-07-22 17:39:02 - Emulator] 2009-07-22 17:39:02.415 emulator[8874:10b] > > Warning once: This application, or a library it uses, is using > > NSQuickDrawView, which has been deprecated. Apps should cease use of > > QuickDraw and move to Quartz. > > [2009-07-22 17:39:21 - MyEventsManager] HOME is up on device > > 'emulator-5554' > > [2009-07-22 17:39:21 - MyEventsManager] Uploading MyEventsManager.apk onto > > device 'emulator-5554' > > [2009-07-22 17:39:21 - MyEventsManager] Installing MyEventsManager.apk... > > [2009-07-22 17:39:30 - MyEventsManager] Application already exists. > > Attempting to re-install instead... > > [2009-07-22 17:39:33 - MyEventsManager] Success! > > [2009-07-22 17:39:33 - MyEventsManager] > > /MyEventsManager/bin/MyEventsManager.apk installed on device > > [2009-07-22 17:39:33 - MyEventsManager] Done! > > -- > Dianne Hackborn > Android framework engineer > hack...@android.com > > Note: please don't send private questions to me, as I don't have time to > provide private support, and so won't reply to such e-mails. 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---