Android process produces logcat “has died” message very often.

前端 未结 2 1114
执笔经年
执笔经年 2020-12-15 22:25

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 no

2条回答
  •  佛祖请我去吃肉
    2020-12-15 23:18

    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.

提交回复
热议问题