简体   繁体   English

一个小时后,Android杀死了我的应用程序

[英]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. 我正在编写一个具有Foreground服务的应用程序,该服务定期使用GPS来获取用户位置。 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. 前地面一直在工作,应用程序不会耗尽电池,因为我一直都不使用GPS。 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. 我的问题是,在应用程序处于后台状态(或多或少)一小时后,Android在前台服务仍在运行时杀死了我的应用程序。 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. 看来这是由于内存使用情况所致,但是我正在检查我的应用程序,它并没有占用大量内存,只不过是像facebook这样的应用程序,它整夜保持打开状态而不关闭。

any suggestion how to keep the application alive or maybe to find out why Android kills my application? 任何建议如何保持应用程序存活,或者找出为什么Android会杀死我的应用程序?

i also check and saw that the average usage if RAM memory is 25M . 我还检查了一下,发现RAM内存为25M时的平均使用量。 is that a lot? 很多吗? could this be the reason ? 这可能是原因吗?

you should check low memory killer. 您应该检查内存不足的杀手.。

PF killed application when low memory. 当内存不足时,PF会终止应用程序。 but PF restart your application Even if it PF killed your application process. 但是PF会重新启动您的应用程序,即使PF杀死了您的应用程序进程。

so your application should restart your service action. 因此您的应用程序应重新启动服务操作。 maybe PF call only Service#onCreate()!! 也许PF只调用Service#onCreate()! Application#onCreate()!! 应用程序#onCreate()!


[ps] If you want to create low memory killer state. [ps]如果要创建低内存杀手状态。 I recommend follwing my application. 我建议取消我的申请。

  • following site ttps://github.com/kyorohiro/KyoroHelloAndroid KyoroStress.apk 以下网站ttps://github.com/kyorohiro/KyoroHelloAndroid KyoroStress.apk
  • or, search "kyoro stress" in google play 或者,在Google Play中搜索“ kyoro Stress”

I recommend to use Service#strartForground method. 我建议使用Service#strartForground方法。 PF killed priority is fall PF被杀的优先权是秋天


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. 这是Android的一项功能,它允许用户打开多个应用程序,但系统会决定何时需要关闭这些应用程序。

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. 如果希望该程序持续很长时间,则应创建一个在背面运行的服务,该服务类似于计算机中的Windows服务。 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 要了解更多有关此内容的信息,您应该使用Google这些主题:-Android服务-阅读/书写偏好设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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