Android的过程中产生的logcat"死亡"消息非常频繁。过程中、频繁、消息、Android

2023-09-04 04:57:04 作者:远山寻你

我的工作是作为一项服务运行,并等待消息的应用程序。当我检查日志,我发现,机器人杀死并重新启动多个进程往往!这不仅发生在我的应用程序,但是是相同的许多其他服务。

我看不出有任何理由和我的设备有足够的内存。我测试了索尼的Xperia正在竞选的Andr​​oid 4.0.4。这是正常的还是错误?

下面是日志的一部分,给大家展示一下我的意思是:

02-04 15:02:38.791 320 332我ActivityManager:过程com.android.email(PID 32763)已死亡。 02-04 15:02:38.791 320 332W¯¯ActivityManager:坠毁服务com.android.email/.service.MailService在5000毫秒调度重启

...... 13分钟后:

02-04 15:15:32.601 320 694我ActivityManager:过程com.android.email(PID 1453)已死亡

解决方案

这是正常的,操作系统做到这一点regulary。

为什么? 每一个应用程序或服务不活动时,或者在后台保留在内存中,直到Android的内存管理器决定它要么占用太多的内存什么,或者当另一个活动的应用程序/服务需要它。例如,当你点击家居按钮,当你在你的电子邮件应用程序。它会返回到你的时候重新打开该应用程序是的确切地点。因为这个程序只是简单地暂停和某种在内存休眠模式。除非Android的需要来分配内存为别的,它一直在那里。的

一个方法,以确保操作系统不杀你的服务,创造一个持续性的服务。

Android Studio的LogCat在哪里

您只能使你的服务持续性,如果您正在开发的系统的应用程序。这些服务将基本取消killable,并标记为在亚行外壳dumpsys活动命令的输出PERS。

HTTP://www.androidguys .COM / 2009/09/09 /钻石 - 是 - 永远 - 服务 - 是 - 不是/

不过:

请使用 AlarmManager IntentService ,所以你的服务并不需要在内存中,除非它是做有意义的工作。这也意味着Android是相当不可能杀死你服务,而你是在内存中,用户不太可能杀死你的服务,因为他们认为你是在浪费内存。

I am working on an app that runs as a service and waits for a message. After I check the log, I find out that Android kills and restarts many processes very often! This not only happens to my app, but is the same for many other services.

I cannot see any reason for this and my device has enough memory. I test with a Sony Xperia S running Android 4.0.4. Is this normal or a bug?

Here is a part of the log to show you what I mean:

02-04 15:02:38.791 320 332 I ActivityManager: Process com.android.email (pid 32763) has died. 02-04 15:02:38.791 320 332 W ActivityManager: Scheduling restart of crashed service com.android.email/.service.MailService in 5000ms

.... and 13 minutes later :

02-04 15:15:32.601 320 694 I ActivityManager: Process com.android.email (pid 1453) has died.

解决方案

It's normal, the OS does this regulary.

Why? Every App or Service when inactive or in the background remains in memory until Android memory manager decides it is either taking up too much memory for nothing, or when another active app/service needs it. For example when you hit the home button when you are in your e-mail app. It will return to the exact place where you were when re-opening the app. Because this app was simply paused and in some sort of hibernation mode in the memory. Unless Android needs to allocate that memory for anything else, it keeps it there.

A way to make sure the OS does not kill your service, is creating a persistant service.

You can only make your service persistent if you are developing system apps. These services will be basically un-killable, and are labeled as "PERS" in the output of the "adb shell dumpsys activity" command.

http://www.androidguys.com/2009/09/09/diamonds-are-forever-services-are-not/

But:

Please use AlarmManager and an IntentService, so your service does not need to be in memory except when it is doing meaningful work. This also means Android is rather unlikely to kill your service while you are in memory, and users are unlikely to kill your service because they think you are wasting memory.

 
精彩推荐