3

Is there a way to cause my app to update itself at exactly midnight every night? I need the new content to be displayed on the app right when it hits midnight. I have an idea of how to accomplish this, but if it isn't in another thread and is in the onCreate and the app is running in the background next time it is opened it would just display the previous info and not the updated?

I could also use help accomplishing this same thing with iPhone as well.

I will clarify a bit. So all the information that is to be displayed on the app will be in the app already. I simply want the content (whats displayed) on the app to randomize and then display the new group of content only once per 24hours or at exactly midnight. Hope that makes it more clear.

steven
  • 698
  • 3
  • 8
  • 32

5 Answers5

2

Android:

You can set pre-determined times to update with AlarmManager

You can look at a snippet here: Android: How to use AlarmManager


iPhone:

With iPhone you probably have to download the content whenever you re-open the app.

Community
  • 1
  • 1
neteinstein
  • 17,529
  • 11
  • 93
  • 123
  • In that code block that was accepted in that link. Would you happen to know a good way to make it happen at midnight each day for example? That one is set up to go off every allotted amount of time after it is created. – steven Jan 09 '12 at 18:33
  • My only suggestion without changing the logic very much is when you start the AlarmManager you calculate how much time is left until midnight and set that. Then the next will be just 24 hours. – neteinstein Jan 10 '12 at 10:08
1

Can't you just have the app update the content upon launch, or when entering the foreground in the appDelegate.

Hubert Kunnemeyer
  • 2,261
  • 1
  • 15
  • 14
0

This question is very vague - but if I understand the requirements correctly you will need to serve the application's content dynamically via a content server (or some type of a CDN). In this case there could be various scenarios.

In the easiest possible implementation, you could have the application be powered by data (XML, JSON, etc...) from something like Amazon S3 and have logic within the application to know how to fetch the correct data depending on the current day.

This wouldn't be extremely difficult to implement, but it would require building some type of cross-platform framework that reads the same kind of data for each application.

dtuckernet
  • 7,817
  • 5
  • 39
  • 54
  • Not quite a server thing because all the content will be on the app already. I clarified above. – steven Jan 09 '12 at 18:27
  • Ah - then my answer changes :). At this point - it is just as simple as keeping track of what content the user has seen and serving new random content based on the time of day and what the user hasn't seen. Even easier :). – dtuckernet Jan 09 '12 at 18:29
  • but I still wonder, how the app (iOS) will check a CDN at 12:00 AM; if it's not running? – Prashant Rane Jan 09 '12 at 18:30
  • Well I'm still a bit new with iPhone, but every time you enter the app it is opening up a fresh instance of the app correct? If so it only needs to happen when the app is opened... BUT I still would need a timer or something that is able to check if it is past midnight from the previous day. – steven Jan 09 '12 at 18:35
  • Exactly - it doesn't matter if the application is closed because the user isn't looking at it :). It just needs to update once the user opens the application. The application would check each time it launches (or is brought to the foreground) to see the current time. It can make changes at that points. No timers would be needed. – dtuckernet Jan 09 '12 at 19:05
0

Is the content available before midnight?

If so, can't you have the app download it in the background beforehand and then make it available exactly at midnight?

If not, there's surely going to be some delay anyway.

Matt
  • 9,068
  • 12
  • 64
  • 84
-1

app can not update itself at least in iOS apps.

Prashant Rane
  • 436
  • 4
  • 11