Android 中的 Unix 信号
我有一个加载本机库的活动。在本机库中,我应该捕获 unix 终止信号吗?我已经尝试过,但无法困住他们。
在本机库中,
void SignalHandler (int signal)
{
__android_log_print(ANDROID_LOG_INFO, TAG, "SignalHandler");
__android_log_print(ANDROID_LOG_INFO, TAG, "signal = %d", signal);
// Do something
}
// Will be called from MainActivity.onCreate()
void NativeFunction (JNIEnv* env, jobject obj) (
JNIEnv* env,
jobject /* this */) {
__android_log_print(ANDROID_LOG_INFO, TAG,"NativeFunction ");
__android_log_print(ANDROID_LOG_INFO, TAG, "Registering for signals...");
if (signal(SIGTERM, SignalHandler) == SIG_ERR)
__android_log_print(ANDROID_LOG_INFO, TAG, "Registering for SIGTERM failed!");
if (signal(SIGINT, SignalHandler) == SIG_ERR)
__android_log_print(ANDROID_LOG_INFO, TAG, "Registering for SIGINT failed!");
__android_log_print(ANDROID_LOG_INFO, TAG, "Successfully registered for signals!");
}
我从最近使用的屏幕向上滑动或通过按“后退”按钮关闭活动...但没有收到任何终止信号(按预期调用了活动的生命周期回调)。
问题是,我应该编写信号处理程序来处理这些(SIGINT 和 SIGBREAK)信号吗? 我只测试了这两种方式(向上滑动和按后退按钮),但 Android 有很多方法可以终止应用程序。我会在 Android 环境中收到 SIGTERM、SIGINT 或其他信号(期望应用程序退出)吗? 我还没有在文档中找到任何内容(到目前为止)。
I have an Activty which loads a native library. In the native library, should I catch the unix termination signals? I have tried, but unable to trap them.
In the native library,
void SignalHandler (int signal)
{
__android_log_print(ANDROID_LOG_INFO, TAG, "SignalHandler");
__android_log_print(ANDROID_LOG_INFO, TAG, "signal = %d", signal);
// Do something
}
// Will be called from MainActivity.onCreate()
void NativeFunction (JNIEnv* env, jobject obj) (
JNIEnv* env,
jobject /* this */) {
__android_log_print(ANDROID_LOG_INFO, TAG,"NativeFunction ");
__android_log_print(ANDROID_LOG_INFO, TAG, "Registering for signals...");
if (signal(SIGTERM, SignalHandler) == SIG_ERR)
__android_log_print(ANDROID_LOG_INFO, TAG, "Registering for SIGTERM failed!");
if (signal(SIGINT, SignalHandler) == SIG_ERR)
__android_log_print(ANDROID_LOG_INFO, TAG, "Registering for SIGINT failed!");
__android_log_print(ANDROID_LOG_INFO, TAG, "Successfully registered for signals!");
}
I swiped up from the recents screen or closed the Activity by pressing the Back button...but didn't get any termination signals (lifecycle callbacks of the Activity were called - as expected).
The question is, should I be writing signal handlers to handle these (SIGINT and SIGBREAK) signals?
I have only tested these two ways (swipe up and back button press), but there are many ways for Android to terminate an app. Will I ever get SIGTERM, SIGINT or other signals (which expects the application to exit) in the Android environment?
I haven't found anything (so far) in the docs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论