安卓:处理连续从服务器拉的最佳方式? [英] Android: Best way of handling continuous pulling from server?

查看:122
本文介绍了安卓:处理连续从服务器拉的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要开始,我要指出,我在的Andr​​oid(Java中没有那么多经验,在所有TBH)的新手,所以很容易在我身上。

To start of, i should mention that i'm a newbie in Android (Not that much experience in Java at all tbh), so be easy on me.

我在做,不断地从服务器中提取数据,然后通过一个HTTP POST请求返回数据的应用程序。现在的问题是,什么是处理实际从服务器拉的最佳方式?我应该使用的AsyncTask或创建另一个线程,并让它在运行?是否有此目的更好的方法?

I am making an app that continuously pulls data from a server, and then returns data through a http post request. The question is, what is the best way to handle the actual pulling from the server? Should i be using AsyncTask or create another thread and let it run on that? Are there better methods for this purpose?

我将拉动数据每5分钟。 (我知道,这将耗尽电池非常快,而且我应该肯定使用机器人C2DM框架。但是我以前有没有它的经验和我在一个最后期限,所以这将不得不做,直到我有时间学习如何实现它。)

I will be pulling data every 5 minutes. (I am aware that this will drain the battery very fast, and i should definately be using Androids C2DM framework. But i have no experience in it before and i'm on a deadline, so this'll have to do until i have time to learn how to implement it.)

我的任何意见感谢!

推荐答案

你需要提取数据背景(即使您的应用程序没有开张,而Android设备处于睡眠状态)?我想你想要什么,因为你提到C2DM多数民众赞成。如果so..the流行语是AlarmManager(含重复时间)/广播接收器,也许NotificationManager通知用户。随着AlarmManager您安排您的活动(每5分钟),并用广播接收器收到这些事件,做你想做的每5分钟的内容:)

Do you need to pull the data in background (even if your app is not "opened" and the android device is sleeping)? I suppose thats what you want because you mentioned C2DM. If so..the buzzwords are AlarmManager (with repeating time)/BroadCastReceiver and maybe NotificationManager to notify the user. With AlarmManager you schedule your events (every 5 minutes) and with BroadcastReceiver you receive those events and do what you want to do every 5 minutes :)

这篇关于安卓:处理连续从服务器拉的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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