Android está matando el proceso / actividad en segundo plano - ¿Cómo puedo evitar esto?

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?

preguntado el 08 de noviembre de 11 a las 16:11

2 Respuestas

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.

respondido 09 nov., 11:00

Thanks, I'll give it a try :-) - Ronny

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.

respondido 08 nov., 11:20

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

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.