0

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 ?

user958880
  • 487
  • 1
  • 7
  • 18
  • you could increase the priority of the app/process to stop android from killing it. Also it could be another program that is taking to many resources and yours is getting killed because its been on for so long and it has probably not been defined as a service. – L7ColWinters Mar 17 '12 at 07:59
  • actually it was the only open application. that's way it's wired that android suddenly killed it. any ideas? – user958880 Mar 17 '12 at 08:19
  • "I'm writing an application that has a Foreground service that use GPS periodically to get the user location." -- use `AlarmManager` and a polling mechanism rather than an everlasting service. See https://github.com/commonsguy/cwac-locpoll and https://github.com/alexbirkett/cwac-locpoll for implementations of this pattern. – CommonsWare Mar 17 '12 at 11:33

2 Answers2

1

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.

  • following site ttps://github.com/kyorohiro/KyoroHelloAndroid KyoroStress.apk
  • or, search "kyoro stress" in google play

I recommend to use Service#strartForground method. PF killed priority is fall


and you may check here

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
kyorohiro
  • 21
  • 4
0

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

Mathew Kurian
  • 5,949
  • 5
  • 46
  • 73
  • I'm already using services, i wrote it in my question. Thanks any how. – user958880 Mar 17 '12 at 08:20
  • In that case, your service should access and change the SHaredPreferences. Tell your application to load its content based on what is indicated by the SharedPreferences. – Mathew Kurian Mar 17 '12 at 08:25
  • 3
    Your service should _not_ be counting on your application(Activity's) to be running in order for it to function, it should be able to run correctly irrespective of whether or not your application is running. – Kai Mar 17 '12 at 09:04