本文介绍了如何像系统服务一样永久运行android服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在安装应用程序后运行我的Android服务(实时通知服务),并强制使其即使关闭应用程序也能正常工作.该服务负责监听我的实时通知服务器,当收到通知时,我会创建Android通知,如果关闭,则可能会运行我的应用程序.我认为我的方法在这种情况下是不正确的,还有另一种使用实时通知的方法.如果您提供一些链接或一些小小的解释,我将不胜感激.

I want to run my Android service(real-time notification service) after application installed and force it to work even application closed. This service responsible for listening my real-time notification server, when notification received I create Android notification and maybe run my app, if it is closed. I assume that my way is not correct for this case and there is another way working with real-time notification. I will be grateful if you give some link or a small explanation.

推荐答案

监听我的实时通知服务器的更好方法,您必须使用GCM. 此处,您可以开始阅读有关GCM的内容.如果您想自己实现它,则必须自己编写服务.例如:

the better approach to listening my real-time notification server, you've to use GCM. here you can start reading about GCM. and if you want to implement it yourself you have to write a service yourself. ex:

    public class ListenerService extends Service{
     @Override
     public void onStartCommand(Intent intent, int flags, int startId){


       return START_STICKY; //this will restart your service even though the system kills
      }

   // you can write other listener service method inside the service
    }

但是我仍然建议您使用GCM或其他云消息传递服务,而不要编写自己的服务.

but still I recommend you to use GCM or other cloud messaging services instead of writing your own.

这篇关于如何像系统服务一样永久运行android服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 17:29