You need to create a countdown timer in the program (days only) before the event.

I.e:
There are 5 days left until the release of the new version, so that every time the user logs in, this information is displayed to him.

Found here information on how to do it. Only if you exit the program, the reset begins again. The comments indicate that you need a service. What is this service, how to do it?
I beg you to tell, since I'm new to Android.

  • Where do you get the date to which you need to count the days? - pavlofff
  • Well, you know that the release is August 1, and how does the application know about it? Deadlines .. date on the server .. Will you send SMS? - pavlofff

1 answer 1

You just need to calculate how many days are left before the release date from the current date, why the service if the user opens the application.

here hold an example, for activity

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... всякий дурацкий код long dataReliza=new GregorianCalendar(2015, 07, 28).getTimeInMillis(); String toRelizeDayStr=getDaysToEvent(dataReliza,null,this); Toast.makeText(this, "До релиза осталось "+toRelizeDayStr+" дней." , Toast.LENGTH_LONG).show(); } public static String getDaysToEvent(long datetime, long now, Context context) { Calendar mCalendar = Calendar.getInstance(); if (now != 0) { mCalendar.setTimeInMillis(now); } mCalendar.set(Calendar.HOUR_OF_DAY, 0); mCalendar.set(Calendar.MINUTE, 0); mCalendar.set(Calendar.SECOND, 0); mCalendar.set(Calendar.MILLISECOND, 0); long daynow = mCalendar.getTimeInMillis(); // обнуление datetime mCalendar = Calendar.getInstance(); mCalendar.setTimeInMillis(datetime); mCalendar.set(Calendar.HOUR_OF_DAY, 0); mCalendar.set(Calendar.MINUTE, 0); mCalendar.set(Calendar.SECOND, 0); mCalendar.set(Calendar.MILLISECOND, 0); long daytime = mCalendar.getTimeInMillis(); int sysDay = (int) (daynow / 86400000);// 1000*60*60*24= 86400000 int dateDay = (int) (daytime / 86400000); // Locale.getDefault().getDisplayLanguage() int raznost = Math.abs(sysDay - dateDay); String raznostText; if (raznost < 10) raznostText = " " + Integer.toString(raznost) + " "; else raznostText = Integer.toString(raznost); return raznostText; } 
  • I think the name of the method, like getDaysToEvent() would be more appropriate. Transliteration from Russian in names scares :) - pavlofff
  • This is because you have not worked for 10 years 1C as a programmer like me :) - Evgeny Karavashkin
  • @pavlofff, I want to install it myself (date). - Dmitry
  • @pavlofff, for example, I know that the new version will be released on August 1. Then I want to write in the application that “8 days left until the release”, and tomorrow, at the entrance, so that it says “7 days left” and so on. Is it possible - Dmitry
  • Duck you instead of dataReliza - set your date variable. I wrote you a function that will tell you how many days are left until the specified date. - Evgeny Karavashkin 5:09