如何显示从后台服务的通知? [英] How to show notification from background service?

查看:99
本文介绍了如何显示从后台服务的通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作的项目有两个不同的应用程序,1是服务器和其他的客户端。服务器应用程序有1个服务类,从而启动服务器线程在 onStartCommand()功能。服务器Thread类服务类本身的定义。当服务器从客户端接收任何数据就存储在数据库中。所以问题是,我想通知新数据已通过通知或吐司消息为准可能到达用户。还告诉我在哪里,我应该写code通知,我是否应该写在服务类或线程类或 firstActivity 类从我开始的服务器服务。谢谢你。

The project I am working on has two different apps, 1 is server and other is client. Server app has 1 service class, which initiates server thread in onStartCommand() function. Class for server thread is defined in service class itself. Whenever server receives any data from client it stores in the database. So problem is, I want to notify user that new data has been arrived through notification or toast message whichever possible. Also tell me where should I write code for notification, whether I should write in service class or thread class or firstActivity class from which i am starting server service. Thank you.

推荐答案

难道我读这不正确?无论您的服务器的应用程序和您的客户端应用程序都是相同的Andr​​oid设备上?

Am I reading this incorrectly? Both your server app and your client app are both on the same Android device?

在任何情况下,需要通过服务来看看ApiDemos为code的通知。

In any case, take a look at the ApiDemos for code for notifications through a service.

既然你很可能将要处理与远程服务器(而不是本地的),所有与网络相关的延迟问题,我想你最好换在AsyncTask的为您服务。

And since you're probably going to be dealing with a remote server (and not a local one) and all the latency issues associated with the network, I think you better wrap your service in an AsyncTask.

还可以了解广播接收器,注册的广播接收器可以是伟大的方式来触发服务/活动,而不需要拥有自己的服务轮询一个无限循环。

Also learn about Broadcast Receivers, registered Broadcast Receivers can be great way to trigger Services/Activities without the need to have your own Service polling in a loop indefinitely.

这篇关于如何显示从后台服务的通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆