简体   繁体   English

Android无限背景循环发出通知

[英]Android infinite background loop to issue notifications

I'm currently programming an android app, that lets different users duel themselves kinda like the popular app Quizduel. 我目前正在编程一个Android应用程序,该应用程序可以让不同的用户自己像流行的应用程序Quizduel那样进行对决。 Therefore one user answers the questions, the results are sent to a server which stores them in a database. 因此,一个用户回答了问题,结果被发送到服务器,服务器将其存储在数据库中。 The second user can see this duel and answer the same questions too, of which the results are also stored in the database. 第二个用户可以看到该决斗并回答相同的问题,其结果也存储在数据库中。

Now I want to issue a notification on the device of the second user when he has been challenged by someone else. 现在,当第二位用户受到其他人的挑战时,我想在他的设备上发出通知。 I thought the best way to achieve this would be an infinite background loop, which checks all X minutes whether there are new open duels on the server and issues a notification if that's the case. 我认为实现此目标的最佳方法是无限的后台循环,该循环检查所有X分钟的时间,服务器上是否有新的公开决斗,如果是这种情况,则发出通知。

I've seen quite a lot of ways to achieve this, like making use of a Service or an IntentService and I really don't know which of the ways is the best one. 我已经看到了很多实现此目的的方法,例如使用Service或IntentService,但我真的不知道哪种方法是最好的。 I can't use the JobScheduler, cause my minAPI is too low. 我无法使用JobScheduler,因为我的minAPI太低。

I'm sorry if you think this question has been answered before, but I found nothing that met my expectations. 如果您认为以前已经回答了这个问题,对不起,但是我发现没有任何东西符合我的期望。

Thanks in advance. 提前致谢。

You should use FCM (firebase cloud messaging, old name is google cloud messaging) its free up to 5 projects. 您应该使用FCM (Firebase云消息传递,旧名称是Google Cloud Messenger)其免费最多5个项目。 Implementation of this is very simple both on client and server side. 在客户端和服务器端,此实现都非常简单。 In your app you will have service when you will receive notifications, form this service you can send your notification to activity via event bus and show this notification on the screen. 在您的应用中,您将在收到通知时获得服务,通过此服务,您可以通过事件总线将通知发送到活动,并在屏幕上显示此通知。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM