[Solved] Countdown to 3 month period android [closed]


I’m not sure if I understand your question correctly. If you want to invoke some code on May, 17th, you could use AlarmManager.

So, first you have to create Activity or Service (let’s assume latter – ex. MyService) and then use code like that:

Intent intent = new Intent(this, MyService.class);
PendingIntent pi = PendingIntent.getService(
    getApplicationContext(),
    1,
    intent,
    PendingIntent.FLAG_CANCEL_CURRENT);

AlarmManager am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, dateMay17th, pi);

Also, you should avoid solution posted by user1566160 because it assumes your app will be running non-stop from now till May 17th, and one should never assume that.

Edit:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Calendar may17th = Calendar.getInstance();
    may17th.set(Calendar.MONTH, 4);
    may17th.set(Calendar.DAY_OF_MONTH, 17);
    may17th.set(Calendar.HOUR_OF_DAY, 0);
    may17th.set(Calendar.MINUTE, 17);

    if ( Calendar.getInstance().after(may17th) ) {
       setContentView(R.layout.new_layout);
    } else {
       setContentView(R.layout.old_layout);
    }
}

7

solved Countdown to 3 month period android [closed]