Android的服务与被杀&QUOT

Android的服务与被杀&QUOT

本文介绍了Android的服务与被杀"不再想和QUOT; - 如何重新启动呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个服务,不断地收集手机上的传感器数据。该服务应该运行永远,例如只要用户希望,而不是由系统杀死。

We have a Service that continuously collects sensor data on the phone. This service should run "forever", e.g. as long as the user wants, and not be killed by the system.

有关澄清,这项服务的不可以适用于一个应用程序被发布在市场上的普通大众,这是一个科学的研究编写的。因此,在运行的应用程序的人都充分认识到自己的电池将被吸入比平常空快,这是没有问题的。

For clarification, this service is not intended for an app to be released in the market to the general public, it is written for a scientific study. So the people running the app are fully aware that their battery will sucked empty faster than usual, this is no problem.

不管怎么说,我的问题是,该服务被运行了一段时间后死亡。有时候,一个小时后,有时只有经过像7奥德10个小时。

Anyways, my problem is that the service gets killed after a while of running. Sometimes after an hour, sometimes only after like 7 oder 10 hours.

日志-条目时,该服务就会被杀死这个样子的。它只是说的不再需要的,有时甚至不调用的onDestroy(),据我可以告诉。

The Log-Entries when the service gets killed look like this. It just says "no longer want", sometimes without even calling onDestroy(), as far as I can tell.

07-20 17:07:11.593 I/ActivityManager(   85): No longer want my.project.datalogging (pid 23918): hidden #16
07-20 17:07:11.593 I/WindowManager(   85): WIN DEATH: Window{44c61570 my.project.datalogging/my.project.datalogging.DataLoggingApp paused=false}
07-20 17:07:11.603 I/BackgroundService(23925): onDestroy()

或更高版本(在我手动重新启动它):

Or later (after I manually restarted it):

07-20 19:00:49.677 I/ActivityManager(   85): No longer want my.project.datalogging:BackgroundService (pid 24421): hidden #17
07-20 19:00:49.677 I/ActivityManager(   85): No longer want my.project.datalogging (pid 24415): hidden #18
07-20 19:00:49.807    85 10707 I WindowManager: WIN DEATH: Window{44f1ea58 my.project.datalogging/my.project.datalogging.DataLoggingApp paused=false}

我经常看到其他的服务被打死了的不再需要的,然后立即重新开始哗啦啦服务的计划重启的。例如这里runkeeper:

I often see other services being killed with "no longer want" and then immediately restarted with "Scheduling restart of crashed service". For example here with runkeeper:

07-20 17:30:45.503 I/ActivityManager(   85): No longer want com.fitnesskeeper.runkeeper (pid 24090): hidden #16
07-20 17:30:45.603 W/ActivityManager(   85): Scheduling restart of crashed service com.fitnesskeeper.runkeeper/.services.RunKeeperService in 5000ms
07-20 17:33:52.989 I/ActivityManager(   85): Start proc com.fitnesskeeper.runkeeper for service com.fitnesskeeper.runkeeper/.services.RunKeeperService: pid=24292 uid=10099 gids={3003, 1015}

日志显示内存不足的记录。测试是在(几)的Nexus One 2.2(Froyo的FRF91)。

The logs show no record of low memory. Testing is done on (several) Nexus One with 2.2 (Froyo FRF91).

有什么办法,我可以实现我的应用程序,这种行为?自动重启被杀害后?

Is there any way I can achieve this behaviour with my app? Automatic restarting after being killed?

还是这本完全不同的东西,只是看在logcat的相似?

Or this this something totally different that just looks similar in logcat?

如果您需要更多的信息,只是问我会尽量提供它: - )

If you need any more information, just ask and I'll try to provide it :-)

推荐答案

如何启动的服务?您是否尝试过<$c$c>startForeground()?这不是一个绝对的保证,当然,但至少应该延长寿命。

How do you start the service? Have you tried startForeground()? That's not an absolute guarantee, of course, but should at least lengthen the lifespan.

这篇关于Android的服务与被杀&QUOT;不再想和QUOT; - 如何重新启动呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 02:28