Reputation: 100398
I'm building this Android app which runs on data generated by a server. This data can change once a day, but it can also change once every 5 minutes, and this is not predictable. A couple of options occur to me:
AC2DM
. Would this be suitable for my problem? For some of the data the user doesn't need to be notified; in fact, maybe the user never needs to see it. Then, for some of the data the user wants to be notified ASAP, so PUSH would come in handy.The data that is sent is in the same order of magnitude as this example, but can also be no more than 10 lines:
<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>
Any thoughts on this matter?
Upvotes: 0
Views: 267
Reputation: 30988
If you go with the push solution, the workflow would be as simple as the following:
This deals with the polling issue nicely with the upside that your users will almost immediately be working with an updated dataset.
Along the same lines, if your app install base grows out of control, another benefit of using a method like this is that you could stagger the notifications to your clients so as not to hammer your server with everyone trying to download the updated dateset at the same time.
Just a few things you should consider.
Upvotes: 1
Reputation: 25757
I have had a situation very similar to this and I solved it by:
To check if it is newer is up to you. I have used both the file approach you mentioned and looked at the modified date of the file.
The AsyncTask is a way of implementing nice threading in Android, thus your download and update process is done in the background and will not effect the UI. In addition you could change the frequency in the Preferences area (should you build one) so that the user can decide the update frequency themselves.
The Alarm is nice class that allows you to run code at set intervals without the need to have a service running that does nothing of 95% of the time, while still draining battery.
Useful links:
Upvotes: 0