After license activation, the server does not synchronize

Hi,

I am having an issue with receiving license events after activating a license key. It seems that synchronization with the server stops working after the license is activated. I am using the library version 3.28.1.

Case 1: The application starts with an already active license
I launch the application. The application already has an entered license, so during initialization, the IsLicenseGenuine() method returns LA_OK and everything works fine. The application runs with the active license. Then, I change the license status in the dashboard to “Suspended” and after 180 seconds, I receive an event with the LA_SUSPENDED status, which is expected. The application receives this event and the LicenseCallback() method handles it correctly.

Case 2: The application has no license and activates one
I launch the application. The application has no license. I enter the license key and call the ActivateLicense() method, which returns the LA_OK status. Then, just like before, I change the license status in the dashboard to “Suspended.” Despite waiting for about 10 minutes, I do not receive any event.

I would expect to receive events about any status changes in both cases. What am I doing wrong?

To better understand the steps I am taking, I have attached the code:

	public void initialize() throws LicenseException {

        try {
            initializeLicenseProductData();

            LicenseCallbackEventListener licenseEventListener = new LicenseCallbackEventListener();
            LexActivator.SetLicenseCallbackListener(licenseEventListener);

            int status = LexActivator.IsLicenseGenuine();
            switch (status) {
            case LexActivator.LA_OK -> handleLicenseGranted();
            case LexActivator.LA_EXPIRED -> handleLicenseExpired();
            case LexActivator.LA_GRACE_PERIOD_OVER -> handleLicenseGracePeriodOver();
            case LexActivator.LA_SUSPENDED -> handleLicenseSuspended();
            default -> {
                int trialStatus = LexActivator.IsTrialGenuine();
                switch (trialStatus) {
                case LexActivator.LA_OK -> handleTrialGranted();
                case LexActivator.LA_TRIAL_EXPIRED -> handleTrialExpired();
                default -> handleNoLicense();
                }
            }
            }

        } catch (LexActivatorException | IOException e) {
            throw new LicenseException(e);
        }
    }
	
    public void activateLicense(String licenseKey) throws LicenseException {
        try {
            LexActivator.SetLicenseKey(licenseKey);
            int status = LexActivator.ActivateLicense();
            switch (status) {
            case LexActivator.LA_OK -> handleLicenseGranted();
            case LexActivator.LA_EXPIRED -> handleLicenseExpired();
            case LexActivator.LA_GRACE_PERIOD_OVER -> handleLicenseGracePeriodOver();
            case LexActivator.LA_SUSPENDED -> handleLicenseSuspended();
            default -> handleLicenseActivationFailure(status);
            }
        } catch (LexActivatorException e) {
            throw new LicenseException("Error during license activation: ", e);
        }
    }
	
	
	class LicenseCallbackEventListener implements LicenseCallbackEvent {

        @Override
        public void LicenseCallback(int status) {
            switch (status) {
            case LexActivator.LA_OK:
                LOGGER.info("LicenseCallback: The license has been activated.");
                break;
            case LexActivator.LA_EXPIRED:
                LOGGER.info("LicenseCallback: The license has been expired.");
                break;
            case LexActivator.LA_SUSPENDED:
                LOGGER.info("LicenseCallback: The license has been suspended.");
                break;
            default:
                LOGGER.warn(LexActivatorException.getErrorMessage(status));
                break;
            }
        }
    }

Thank you for your help!

Hi Dominika,

In the case of the second flow, you are not setting the license callback. You can set it immediately after setting the license key.

Hi,

I would like to thank you for your help and share some observations regarding the application’s behavior in my flow.

When the application is launching, the initialize() method is always called first. This ensures that if the client had previously entered a license key, the application will start with an active license. Additionally, in the initialize() method, a listener is registered to react to any changes in the license status from that point onwards.

However, if the client has not entered a license key before, the application starts in a no-license mode, allowing the client to manually enter the license key. When this is done, the activateLicense(String licenseKey) method is called.

I would expect that the listener registered in the initialize() method would receive all events related to the currently assigned license, without needing to be set again in the activateLicense(String licenseKey) method.

When I set the listener again in the activateLicense() method, it still does not receive any events. I suspect that it is only possible to set a listener for callback events once. From what I see, the SetLicenseCallbackListener(LicenseCallbackEvent listener) method allows for the registration of only one listener.

The application correctly receives events when I first activate the license key, but only if the listener is not set in the initialize() method (it is set only in the activateLicense() method). Unfortunately, this setup means I cannot track changes in license status when the user has activated the license earlier and is now starting the application with the license already active.

Could you provide guidance on how to address this issue? Any suggestions or insights would be greatly appreciated.

Hi @Dominika,

For first-time users, IsLicenseGenuine() will return LA_FAIL, prompting the users to enter a license key for activation. In this case, you should register the callback after SetLicenseKey() function, since the callback is tied to the license key, the key must be set before calling it so that the callback is registered.

Afterward, the license key will always be defined whenever the program is run so calling SetLicenseCallback() even in the initialization function for the second time will also work.

For users who have already activated the license, since the key is already defined you can call the SetLicenseCallback() before invoking IsLicenseGenuine(). This can also be done in the init function.

Please note that the last registered callback before server synchronization will be honoured. Therefore, during the activation workflow (first time), the callback registered just before ActivateLicense() will take precedence over any previously set callback. For other cases, a callback registered before server sync will be honoured.