I'm writing an application that has a Foreground service that use GPS periodically to get the user location. The fore ground is working all the time and the application doesn't drain the battery because i don't use the GPS all the time. My problem is that after one hour while the application is in the background(more or less) Android kills my application while the foreground service is still running. It seems like it's because of memory usage but i'm checking my application and it doesn't consume a lot of memory, not more than application like facebook that stays open all night without getting closed.
any suggestion how to keep the application alive or maybe to find out why Android kills my application?
i also check and saw that the average usage if RAM memory is 25M . is that a lot? could this be the reason ?
you should check low memory killer.
PF killed application when low memory. but PF restart your application Even if it PF killed your application process.
so your application should restart your service action. maybe PF call only Service#onCreate()!! Application#onCreate()!!
[ps] If you want to create low memory killer state. I recommend follwing my application.
I recommend to use Service#strartForground method. PF killed priority is fall
sample code1 https://github.com/kyorohiro/KyoroHelloAndroid/blob/master/KyoroLogcat/src/info/kyorohiro/helloworld/logcat/KyoroLogcatService.java
sampele code2 https://github.com/kyorohiro/KyoroHelloAndroid/blob/master/KyoroCommon/src/info/kyorohiro/helloworld/android/base/ForegroundService.java
sample code3 https://github.com/kyorohiro/KyoroHelloAndroid/blob/master/KyoroCommon/src/info/kyorohiro/helloworld/android/base/TestService.java
ref
http://developer.android.com/reference/android/app/Service.html#startForeground(int, android.app.Notification)
and you may check here
http://code.google.com/p/android/issues/detail?id=20035
This is a feature of Android that allows users to open multiple applications, but the system decides when it needs to close these applications.
If you want the program to last a long time, you should create a service that runs in the back that is similar to Windows Services in your computer. The user nor the developer can see it visually, but it can make changes according the environment of the phone.
This service can adjust preferences of a certain application and then the application can read these changes and create a visual component when the user opens it.
To learn more about this, you should Google these topics: -Android Services -Reading/Writing Preferences