¿Cambiar enlace para descargar cada 7 días?

I'm downloading a certain website in html format to my device, so that I can display it in webview in offline mode. The only problem is that the link is dynamic, and it changes once a week. To keep the html item updated as much as possible, I want the app to download it once a week.

Let's say for example that this is the websites address:


Next week, the address will be:


And week after that, the website will be:


I already figured I would do this be declaring a variable that would be changing, something like

int week;
String urlToDownload = "www.mywebsite.com/" + week;

But how do I make it so that this variable will change everyday even if the app is not started, or is there a better way to do this?

preguntado el 09 de septiembre de 13 a las 22:09

Have you looked at storing a "start" date and just calculating "today"'s offset from it? -

3 Respuestas

Tal vez puedas usar Administrador de alarmas class. That allows you to plan something on the background, when app is not even running.

I would use the most simple solution. Do you know what time does the URL change? You can always check the time of previous start of application and when next app is started check it and determine how many weeks is from that.

Respondido el 09 de Septiembre de 13 a las 23:09

Use el java.util.Calendar

Calendar calender = Calendar.getInstance();
MyLog.d("Current Week:", "" + calender.get(Calendar.WEEK_OF_YEAR));

This prints "Current Week: 37"

With that maybe you can write code to get the appropriate page. The week nr are kind of static

Respondido el 09 de Septiembre de 13 a las 23:09

You can update the variable during the onStart() phase. Make a constant that has the start date, and then get the current date and figure out the offset. This way even if the app hasnt been started in a long time, once it is started you will have the proper link.

Respondido el 09 de Septiembre de 13 a las 23:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.