简体   繁体   English

当我的应用程序被杀死时如何发送消息(android)

[英]How can I send a message when my app is killed(android)

正常情况下,如果app被杀了,我什么也做不了。通过系统,我不能做任何事情,我不知道如何告诉服务器应用程序被杀死。我知道调用 jni,但我不知道如何编写 jni 代码。有人知道吗?

Try using daemon.尝试使用守护进程。 In that case, you can turn your java process into daemon and finish main one.在这种情况下,您可以将您的 java 进程变成守护进程并完成主进程。

Take a look here:看看这里:

https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo022 https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo022

In general, you want to demonize your native code.通常,您希望妖魔化您的本机代码。

...
...
int demonize() {
  int pid = fork();
  switch ( pid ) {
    case -1:
      return (-1);
    case 0:
      break;
    default:
      return pid;
  }
  return 0;
}
...
...
int pid = demonize();

if( pid == 0 ) {
  while(1) {
    sleep(1);
    fprintf(fid, "daemon\n");
    fflush( fid );
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何从我的Android应用程序发送Skype消息? - how can i send a skype message from My android app? 即使应用程序被杀死,我怎样才能让我的应用程序运行? 从最近的应用程序中删除时在某种意义上被杀死 - How can i make my app run even when app is killed? killed in the sense when it is removed from recent apps 即使应用程序被杀死,如何向Android设备发送推送通知? - How to send push notification to android devices even when app is killed? 如何从Web服务向我的Android应用发送消息 - how can send message to my android app from web service 如何从我的 Android 应用程序通过 WhatsApp 向特定联系人发送消息? - How can I send message to specific contact through WhatsApp from my android app? 当应用程序在后台或被杀死时,如何在收到通知时启动我的应用程序或活动? - how can i launch my app or an activity on notification received when app is in background or killed? 即使我的应用程序被杀死,如何保持我的定位服务运行 - How Can I Keep My Location Service Running Even When My App Is Killed 如何防止我的Android应用/服务被任务管理器“杀死”? - How can I prevent my Android app/service from being “killed” from a task manager? 如何检测我的应用程序何时在 android 中被强行杀死? - How to detect when my app is killed forcefully in android? 当Android杀死我的应用程序时如何存储Cookie信息 - How to store the cookie info when android killed my app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM