当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Handling KILL signal in Service?

问题描述:

I am new to android dev. Our requirement is to run a background service in android. Which is unkillable or it is capable to handle KILL signal from taskmanager..

Is there is any way to do it?

I have heard about addShutdownHandler, But it wont fired when user kills it.

Thanks in advance

网友答案:

From man 7 signal:

The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.

This is fundamentally by kernel design. Think about it: if a process could ignore all signals whatsoever, then how would you stop it if it ran away uncontrolled? No, what you'll have to do is see to it that the KILL signal is not sent. Running your program under its own userid should achieve this, as long as no one with administrative privileges generates the signal -- but even this requirement may be practically impossible to meet. By design, the system provides the basic ability to kill a process, on the theory that the user or sysadmin might (for whatever reason) want the process killed.

网友答案:

Is there is any way to do it?

Only by building your own custom version of Android, with your code in a standard C/C++ daemon, and then distributing a ROM mod that contains that customized version of Android.

If you are trying to create an ordinary SDK app, the user or Android itself can get rid of your process at any time, for any reason.

网友答案:

In general: not possible.

I should add that trying to impose such a requirement makes you sound nefarious -- there's a reason the user is allowed to kill processes.

分享给朋友:
您可能感兴趣的文章:
随机阅读: