Android kills my application after an hour

2019-09-08 11:01发布

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 ?

2条回答
Luminary・发光体
2楼-- · 2019-09-08 11:37

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

查看更多
何必那么认真
3楼-- · 2019-09-08 11:54

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

查看更多
登录 后发表回答