1

I was creating an alarm clock in Java and JavaFX. The problem is that, how can I run that application timer even when the application is closed.

For example:-

A person set an alarm at 9:00 am but the current time is 8:00 am and closes the application, then the scheduled alarm resets and wouldn't​ work (in my case). I want to do like alarm clock in Windows does. Even if a person closes alarm app ,it shows a notification at the specified time and rang up.

I also Google'ed this question but everywhere found about android only and some Alarm Manager feature( about which I don't have any knowledge), that's why I myself posted.

Advance thanks for any help.

6
  • 1
    create a separate Thread, and run it in the background. When time comes, show the notification. May 13, 2017 at 20:28
  • You are trying too hard. Use Windows' task scheduler instead of rolling your own. May 13, 2017 at 22:34
  • @Shashwat Thanks Shashwat , I will try what you said.
    – Weirdoooo
    May 13, 2017 at 22:42
  • Developers don't waste time reinventing the wheel. Your choice, though, whether you want to be a developer, or an overpriced time sink. Good luck. May 13, 2017 at 22:45
  • @IInspectable not reinventing ,just testing myself. Leave I don't have enough time to argue with eccentric people.
    – Weirdoooo
    May 13, 2017 at 22:56

1 Answer 1

2

JavaFX terminates your application when the last stage is closed by default. You can change this behavior by calling Platform.setImplicitExit(false);

Javadoc of Class javafx.application.Application says to the life cycle of application:

Life-cycle

The entry point for JavaFX applications is the Application class. The JavaFX runtime does the following, in order, whenever an application is launched:

  1. Constructs an instance of the specified Application class
  2. Calls the init() method
  3. Calls the start(javafx.stage.Stage) method
    • Waits for the application to finish, which happens when either of the following occur: the application calls Platform.exit()
    • the last window has been closed and the implicitExit attribute on Platform is true
  4. Calls the stop() method

You can implement the invocation of your alarm method over a ScheduledService or any Java based cron framework.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.