tags:

views:

76

answers:

3

Hello,

I have some proccess that i would like to run in the background the whole time. so i made it "service". my question is: is there anyway to prevent from the user to kill this service? (even if he uses third party app)

thanks,

ray.

A: 

See: http://developer.android.com/reference/android/app/Service.html#ProcessLifecycle

Rob Kent
I already have,but how would i keep my service safe, so third party appz like: appKiller, wont be able to kill it anyway?Tnanks,ray,
rayman
As stated above, you cannot guarantee that your service will always be around. What I did with one of mine was for the service to do its work in the background then set an alarm so that it is woken up when it next needs to work. The it shuts itself down. Otherwise register some filters for system events that your service needs to respond to.
Rob Kent
+2  A: 

No, it is not possible. It is also a bad idea.

CommonsWare
yes.. but iam not talking about regular app, i`am talking about some system which i "burn" in the phone system.. and i need this system to work as service all the time, and not letting the user disable that service.. i though about AlarmManager.. what do you think?thanks,ray.
rayman
It is not possible to have an everlasting Android service. You are welcome to write daemons in C/C++ as part of the firmware, and those are unkillable as far as I understand it, but you are better asking questions related to that on the official Android open source project Google Groups at http://source.android.com/discuss
CommonsWare
A: 

Maybe this can help you:

final Intent intent = new Intent(context, YourService.class);
final PendingIntent pending = PendingIntent.getService(context, 0, intent, 0);
final AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarm.cancel(pending);
long interval = 30000;//milliseconds
alarm.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(),interval, pending);

This way your service will be receiving regular onStart events from AlarmManager. If your service is stopped it will be restarted. So you may say it will be running infinitely. More complete sample can be found in Photostream sample application http://code.google.com/p/apps-for-android/.

Fedor
That will not survive a "task killer", at least for current versions of Android. The API the task killers exploit also wipe out a service's alarms.
CommonsWare