Reputation: 5667
For some reason there are processes in my app that continue even after closing the application's window and exiting. Is there something I haven't accounted for? My app periodically generates a system tray notification, but these continue even after exiting. The only way to stop it is to find the java.exe process in the Task Manager. Is there something I'm overlooking?
public class TrayNotification {
public static void execute(String firstName, String incidentNumber, String requestId, TableView tabTable) throws AWTException, MalformedURLException {
if (SystemTray.isSupported()) {
TrayNotification trayNotification = new TrayNotification();
trayNotification.displayTray(firstName, incidentNumber, requestId, tabTable);
}
}
private void displayTray(String firstName, String incidentNumber, String requestId, TableView tabTable) throws AWTException, MalformedURLException {
// Obtain a single instance of SystemTray
SystemTray tray = SystemTray.getSystemTray();
// Set TrayIcon values
Image image = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/tray-icon.png"));
final TrayIcon trayIcon = new TrayIcon(image, "Remedy React Notification");
trayIcon.setImageAutoSize(true);
trayIcon.setToolTip(incidentNumber);
// Add TrayIcon to SystemTray instance if possible
try {
tray.add(trayIcon);
} catch (AWTException e) {
// System.out.println("Notification could not be added.");
}
trayIcon.addActionListener(e -> {
Parent root = null;
try {
root = FXMLLoader.load(getClass().getResource("/fxml/scene.fxml"));
root.requestLayout();
} catch (IOException e1) {
e1.printStackTrace();
}
System.out.println("Test");
});
// Display TrayIcon
trayIcon.displayMessage("Hey, " + firstName, "You are now tracking " + incidentNumber + " !", TrayIcon.MessageType.INFO);
}
}
Upvotes: 0
Views: 484
Reputation: 1030
I am using System.exit(0)
when the user clicks "Exit" button.
Upvotes: 1