实时Android的通知 [英] Android notification in realtime

查看:135
本文介绍了实时Android的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,发送和接收文件。我想建立一个Android应用程序,如果一个新的文件已经收到通知用户的,如果点击该通知显示文档详细信息。它不必是实时的,它可以在五分钟的时间间隔或东西更新

I have a website that sends and receives documents. I was thinking of building an Android app that notifies the user if a new document has been received, and displays document details if the notification is clicked. It doesn't have to be in real time, it could update in interval of five minutes or something.

什么是更新网站的变化的Andr​​oid应用程序的最佳方式?我是新来的Andr​​oid和我不太知道从哪里开始。我听说过服务,BroadcastReceivers和报警的,但我不知道如果这些都是正确的想法。

What is the best way to update the Android app of changes in the website? I'm new to Android and I'm not quite sure where to start. I've heard of Services, BroadcastReceivers and Alarms, but I don't know if those are the right ideas.

更新:我如何在我的广播接收器的AsyncTask的内更新我从我的网站分贝的Andr​​oid分贝?我担心我可能有一个泄漏的错误,有时会用我的AsyncTask来了。

Update: How do I update my Android db from my web db within an AsyncTask in my BroadcastReceiver? I'm worried I might have a "leak error" which sometimes comes up with my AsyncTask.

推荐答案

您可以尝试实施的 GCM 或如上述的,用 AlarmManager 或更有效的的jobscheduler (需要API等级21! )。避免在广播接收器干过重的活。而是使用广播接收器来接收警报,并开始后台服务。您还可以看看到<一个href=\"https://developer.android.com/reference/android/support/v4/content/WakefulBroadcastReceiver.html\"相对=nofollow> WakefulBroadcastReceiver 其持有激活锁定为您服务。该服务可以通过使用REST架构从你的web服务数据并更新它的本地数据库。 改造是一个REST架构的功能强大的开源库。如果有新的数据库记录,您可以通过通知。不要忘记检查基本的东西不一样启动该服务,如果该设备还没有得到网络连接或工作已经结束后停止服务。我个人建议首先学习的基础知识,然后去高级的主题。祝你好运和快乐。

You can try to implement GCM or as the above-mentioned, work with an AlarmManager or the more efficient JobScheduler (requires API level 21!). Avoid doing heavy work on a BroadcastReceiver. Instead use the Broadcastreceiver to receive Alarms and start a Service in background. You may also have a look to WakefulBroadcastReceiver which holds a WakeLock for you. The Service could GET data from your webservice by using a REST architecture and update it's local database. Retrofit is a powerful open source library for a REST architecture. If there are new database records, you can inform the user by a Notification. Don't forget to check basic things like not starting the Service if the device hasn't got a network connection or to stop the Service after the work has been finished. I personally recommend to learn the basics first and then go to advanced topics. Good luck and pleasure.

这篇关于实时Android的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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