I have made an app that runs in the background. The purpose is to intercept incoming calls. After a while Android kills the service/app if it's not "active" for a while. Any way to avoid this in basic4android?
2 Answers
Set the service to be a foreground service. Run Service.StartForeground from the service module When you are finished processing use:Service.StopForeground to stop the service from being a foreground service.

- 138
- 1
- 6
The easiest way to avoid this problem is to place a notification icon in the top bar. Android will not kill processes that have a notification icon unless the phone is running very short on memory.
However, you may want to make this icon an option to the user (default: on), because higher end phones won't kill processes unless they have a memory shortage anyway.
Unfortunately, I don't know how to implement this.
[edit] You could also make the app do something completely pointless every 15 minutes, like set a useless variable. This would classify the application as active to the system. You'd still have to worry about low memory situations, though.

- 23
- 4
-
Thanks for your reply. I have a timer running (in the service that intercept the calls) that does a calculation every 20 second, but Android is still killing the app. I guess I'll try the notification icon. Again, thanks :-) – Ronny Nov 08 '11 at 18:06