我正在构建这个Android应用程序,它运行在服务器生成的数据上。这些数据每天可以更改一次,但也可以每5分钟更改一次,这是不可预测的。 我有几种选择:
AC2DM
。这适合我的问题吗?对于某些数据,用户无需收到通知;事实上,也许用户永远不需要看到它。然后,对于某些数据,用户希望尽快得到通知,因此PUSH会派上用场。发送的数据与此示例的数量级相同,但也可以不超过10行:
<myapp status_code="200">
<match>
<match_id>12</match_id>
<home_team_id>1</home_team_id>
<home_team>ADO Den Haag</home_team>
<away_team_id>3</away_team_id>
<away_team>AZ</away_team>
<home_score>0</home_score>
<away_score>0</away_score>
<datetime>2012-02-08 19:00:00</datetime>
<comp_id>1</comp_id>
</match>
<match>
<match_id>13</match_id>
<home_team_id>7</home_team_id>
<home_team>FC Twente</home_team>
<away_team_id>10</away_team_id>
<away_team>Heracles</away_team>
<home_score>0</home_score>
<away_score>0</away_score>
<datetime>2012-02-10 20:00:00</datetime>
<comp_id>1</comp_id>
</match>
<match>
<match_id>14</match_id>
<home_team_id>3</home_team_id>
<home_team>AZ</home_team>
<away_team_id>5</away_team_id>
<away_team>Excelsior</away_team>
<home_score>0</home_score>
<away_score>0</away_score>
<datetime>2012-02-11 18:45:00</datetime>
<comp_id>1</comp_id>
</match>
<match>
<match_id>15</match_id>
<home_team_id>15</home_team_id>
<home_team>Roda JC</home_team>
<away_team_id>12</away_team_id>
<away_team>NEC</away_team>
<home_score>0</home_score>
<away_score>0</away_score>
<datetime>2012-02-11 19:45:00</datetime>
<comp_id>1</comp_id>
</match>
<match>
<match_id>16</match_id>
<home_team_id>18</home_team_id>
<home_team>VVV Venlo</home_team>
<away_team_id>6</away_team_id>
<away_team>FC Groningen</away_team>
<home_score>0</home_score>
<away_score>0</away_score>
<datetime>2012-02-11 19:45:00</datetime>
<comp_id>1</comp_id>
</match>
<match>
<match_id>17</match_id>
<home_team_id>11</home_team_id>
<home_team>NAC Breda</home_team>
<away_team_id>2</away_team_id>
<away_team>Ajax</away_team>
<home_score>0</home_score>
<away_score>0</away_score>
<datetime>2012-02-11 20:45:00</datetime>
<comp_id>1</comp_id>
</match>
<match>
<match_id>18</match_id>
<home_team_id>8</home_team_id>
<home_team>FC Utrecht</home_team>
<away_team_id>1</away_team_id>
<away_team>ADO Den Haag</away_team>
<home_score>0</home_score>
<away_score>0</away_score>
<datetime>2012-02-12 12:30:00</datetime>
<comp_id>1</comp_id>
</match>
<match>
<match_id>20</match_id>
<home_team_id>13</home_team_id>
<home_team>PSV</home_team>
<away_team_id>4</away_team_id>
<away_team>De Graafschap</away_team>
<home_score>0</home_score>
<away_score>0</away_score>
<datetime>2012-02-12 14:30:00</datetime>
<comp_id>1</comp_id>
</match>
<match>
<match_id>21</match_id>
<home_team_id>14</home_team_id>
<home_team>RKC Waalwijk</home_team>
<away_team_id>16</away_team_id>
<away_team>SC Heerenveen</away_team>
<home_score>0</home_score>
<away_score>0</away_score>
<datetime>2012-02-12 14:30:00</datetime>
<comp_id>1</comp_id>
</match>
<match>
<match_id>22</match_id>
<home_team_id>9</home_team_id>
<home_team>Feyenoord</home_team>
<away_team_id>17</away_team_id>
<away_team>Vitesse</away_team>
<home_score>0</home_score>
<away_score>0</away_score>
<datetime>2012-02-12 16:30:00</datetime>
<comp_id>1</comp_id>
</match>
</myapp>
对此事有何想法?
答案 0 :(得分:1)
如果您使用推送解决方案,工作流程将如下所示:
这很好地处理了轮询问题,您的用户几乎可以立即使用更新的数据集。
同样,如果您的应用安装基础失控,使用此类方法的另一个好处是您可以错开通知客户端以免所有人试图同时下载更新的日期集来锤击您的服务器。
您应该考虑的一些事情。
答案 1 :(得分:0)
我的情况与此非常相似,我通过以下方式解决了这个问题:
要检查它是否更新取决于您。我已经使用了你提到的文件方法,并查看了文件的修改日期。
AsyncTask是一种在Android中实现良好线程的方式,因此您的下载和更新过程在后台完成,不会影响UI。此外,您可以更改“首选项”区域中的频率(如果您构建一个频率),以便用户可以自行决定更新频率。
警报是一个很好的类,它允许你以设定的间隔运行代码,而不需要运行95%的时间都没有运行的服务,同时仍然耗尽电池电量。
有用的链接: