简体   繁体   中英

Android kills my application after an hour

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.

  • 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM